diff --git a/upload-image/notes.txt b/upload-image/notes.txt deleted file mode 100644 index 314c5cc..0000000 --- a/upload-image/notes.txt +++ /dev/null @@ -1,35 +0,0 @@ -This will embed the selected image into the generated images which probably isnt desired -Havent checked if there is a better way to filter these out. -Current fix for this is to add this to execution.py: - -def prune_prompt(prompt): - pruned_prompt = {} - for n in prompt: - class_type = prompt[n]['class_type'] - class_def = nodes.NODE_CLASS_MAPPINGS[class_type] - valid_inputs = class_def.INPUT_TYPES() - pruned_prompt[n] = copy.deepcopy(prompt[n]) - - if "inputs" in pruned_prompt[n]: - for x in pruned_prompt[n]["inputs"]: - input_type = None - if ("required" in valid_inputs and x in valid_inputs["required"]): - input_type = valid_inputs["required"][x] - elif ("optional" in valid_inputs and x in valid_inputs["optional"]): - input_type = valid_inputs["optional"][x] - - if input_type is not None and input_type[0] == "B64IMAGE": - pruned_prompt[n]["inputs"][x] = None - - return pruned_prompt - - -And call that from - if h[x] == "PROMPT": - input_data_all[x] = prune_prompt(prompt) - - -It also requires increasing the maximum request size on the API in server.py - self.app = web.Application(client_max_size=20971520) - -Or some other sensible limit diff --git a/upload-image/uploadImage.js b/upload-image/uploadImage.js deleted file mode 100644 index 3237dd3..0000000 --- a/upload-image/uploadImage.js +++ /dev/null @@ -1,54 +0,0 @@ -import { app } from "/scripts/app.js"; - -// Adds a new UploadImage node - -const toBase64 = (file) => - new Promise((resolve, reject) => { - const reader = new FileReader(); - reader.readAsDataURL(file); - reader.onload = () => resolve(reader.result); - reader.onerror = (error) => reject(error); - }); - -app.registerExtension({ - name: "Comfy.UploadImage", - async getCustomWidgets() { - return { - B64IMAGE(node) { - let uploadWidget; - const fileInput = document.createElement("input"); - - Object.assign(fileInput, { - type: "file", - accept: "image/jpeg,image/png", - style: "display: none", - onchange: () => { - if (fileInput.files.length) { - const img = new Image(); - img.onload = () => { - node.imgs = [img]; - }; - toBase64(fileInput.files[0]).then((d) => { - img.src = d; - }); - } - }, - }); - document.body.append(fileInput); - - uploadWidget = node.addWidget("button", "image", "image", () => { - fileInput.click(); - }); - - uploadWidget.serializeValue = () => { - if(node.imgs && node.imgs.length) { - return node.imgs[0].src; - } - return null; - }; - - return { widget: uploadWidget }; - }, - }; - }, -}); diff --git a/upload-image/upload_image.py b/upload-image/upload_image.py deleted file mode 100644 index 236f17e..0000000 --- a/upload-image/upload_image.py +++ /dev/null @@ -1,35 +0,0 @@ -from PIL import Image -import numpy as np -import torch - - -class UploadImage: - @classmethod - def INPUT_TYPES(s): - return {"required": - {"image": ("B64IMAGE",)}, - } - - CATEGORY = "image" - - RETURN_TYPES = ("IMAGE",) - FUNCTION = "load_image" - - def load_image(self, image): - from io import BytesIO - import re - import base64 - if image.startswith("data:image/"): - image_data = re.sub('^data:image/.+;base64,', '', image) - i = Image.open(BytesIO(base64.b64decode(image_data))) - else: - raise Exception("Invalid image data") - - image = i.convert("RGB") - image = np.array(image).astype(np.float32) / 255.0 - image = torch.from_numpy(image)[None,] - return (image,) - -NODE_CLASS_MAPPINGS = { - "UploadImage": UploadImage, -}