feat: added image_from_url node

This commit is contained in:
jitcoder
2024-01-28 20:09:40 +05:00
parent 48c2f45218
commit 73d4160354
7 changed files with 116 additions and 25 deletions
+2
View File
@@ -0,0 +1,2 @@
db.json
__pycache__
+17 -1
View File
@@ -1,3 +1,19 @@
from .lora_info import NODE_CLASS_MAPPINGS,WEB_DIRECTORY,NODE_DISPLAY_NAME_MAPPINGS
from .lora_info import LoraInfo
from .image_from_url import ImageFromURL
# A dictionary that contains all nodes you want to export with their names
# NOTE: names should be globally unique
NODE_CLASS_MAPPINGS = {
"LoraInfo": LoraInfo,
"ImageFromURL": ImageFromURL
}
# A dictionary that contains the friendly/humanly readable titles for the nodes
NODE_DISPLAY_NAME_MAPPINGS = {
"LoraInfo": "Lora Info",
"ImageFromURL": "Image From URL"
}
WEB_DIRECTORY = "./js"
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS", "WEB_DIRECTORY"]
Binary file not shown.

After

Width:  |  Height:  |  Size: 180 KiB

+30
View File
@@ -0,0 +1,30 @@
from PIL import Image, ImageOps
import requests
import torch
import numpy
class ImageFromURL:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"url": ("STRING", {"multiline": False})
},
}
RETURN_NAMES = ("image",)
RETURN_TYPES = ("IMAGE",)
FUNCTION = "fetch_image"
OUTPUT_NODE = True
CATEGORY = "jitcoder"
def fetch_image(self, url):
image = Image.open(requests.get(url, stream=True).raw)
image = ImageOps.exif_transpose(image)
image = image.convert("RGB")
image = numpy.array(image).astype(numpy.float32) / 255.0
image = torch.from_numpy(image)[None,]
return (image,)
+39
View File
@@ -56,3 +56,42 @@ app.registerExtension({
}
},
});
app.registerExtension({
name: "ImageFromURL",
async beforeRegisterNodeDef(nodeType, nodeData, app) {
if (nodeData.name === "ImageFromURL") {
const onNodeCreated = nodeType.prototype.onNodeCreated;
nodeType.prototype.onNodeCreated = function () {
onNodeCreated ? onNodeCreated.apply(this, []) : undefined;
const [urlWidget] = this.widgets;
let originalDescriptor = Object.getOwnPropertyDescriptor(urlWidget, 'value');
Object.defineProperty(urlWidget, 'value', {
get() {
const ret = originalDescriptor.get?.call(urlWidget) || originalDescriptor.value || '';
return ret
},
set(value) {
if (originalDescriptor.set) {
originalDescriptor.set.call(urlWidget, value);
} else {
originalDescriptor.value = value;
}
const body = new FormData();
body.append('url',value);
api
.fetchApi("/fetch_image", { method: "POST", body, })
.then((resp) => {
})
}
});
}
}
},
});
-15
View File
@@ -3,7 +3,6 @@ import hashlib
import requests
import json
import server
from server import PromptServer
from aiohttp import web
import os
@@ -114,9 +113,6 @@ async def fetch_lora_info(request):
return web.json_response({"output": output, "triggerWords": triggerWords, "examplePrompt": examplePrompt, "baseModel": baseModel})
dictionary_of_stuff = {"something":"A text message"}
PromptServer.instance.send_sync("my-message-handle", dictionary_of_stuff)
class LoraInfo:
def __init__(self):
pass
@@ -139,15 +135,4 @@ class LoraInfo:
(output, triggerWords, examplePrompt, baseModel) = get_lora_info(lora_name)
return {"ui": {"text": (output,), "model": (baseModel,)}, "result": (triggerWords, examplePrompt)}
# A dictionary that contains all nodes you want to export with their names
# NOTE: names should be globally unique
NODE_CLASS_MAPPINGS = {
"LoraInfo": LoraInfo,
}
# A dictionary that contains the friendly/humanly readable titles for the nodes
NODE_DISPLAY_NAME_MAPPINGS = {
"LoraInfo": "Lora Info",
}
WEB_DIRECTORY = "./js"
+28 -9
View File
@@ -1,3 +1,27 @@
# Contains 2 Nodes
- Lora Info
- Image From URL
Apologies for shoving another node into this repo, I'll eventually create a new repo for the Image From URL
## Installation
#### Method 1.
Open ComfyUI Manager, search for "lorainfo", or "jitcoder", click install
#### Method 2.
Inside ComfyUI/custom-nodes
```sh
git clone https://github.com/jitcoder/lora-info.git
```
#### Method 3.
Download this repo as a zip and extract in the custom-nodes directory.
## Lora Info
Shows Lora Base Model, Trigger Words and Examples
@@ -9,15 +33,10 @@ Special thanks to:
![image](preview.png)
## Installation
Inside ComfyUI/custom-nodes
## Image From URL
```sh
git clone https://github.com/jitcoder/lora-info.git
```
Or download this repo as a zip and extract in the custom-nodes directory.
Restart ComfyUI
Loads an image from the URL and makes it available for use in your workflow. This is especially useful if you intend on
sharing your workflows and want to make it easier for users to use them instead of having to download images separately.
![image](image-from-url.png)