diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d828502 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +db.json +__pycache__ \ No newline at end of file diff --git a/__init__.py b/__init__.py index 5abd77c..c228ad7 100644 --- a/__init__.py +++ b/__init__.py @@ -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"] \ No newline at end of file diff --git a/image-from-url.png b/image-from-url.png new file mode 100644 index 0000000..6c1c29d Binary files /dev/null and b/image-from-url.png differ diff --git a/image_from_url.py b/image_from_url.py new file mode 100644 index 0000000..0bd52d2 --- /dev/null +++ b/image_from_url.py @@ -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,) diff --git a/js/index.js b/js/index.js index 94b9493..99bd05c 100644 --- a/js/index.js +++ b/js/index.js @@ -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) => { + + }) + } + }); + } + } + }, +}); \ No newline at end of file diff --git a/lora_info.py b/lora_info.py index c5cc833..aa911de 100644 --- a/lora_info.py +++ b/lora_info.py @@ -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" diff --git a/readme.md b/readme.md index cd23f88..e1d72e8 100644 --- a/readme.md +++ b/readme.md @@ -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)