From a535cd0c9372dd86f7b8cdb0deceed9710be788c Mon Sep 17 00:00:00 2001 From: iwindy910 Date: Mon, 12 Jan 2026 14:37:34 +0800 Subject: [PATCH] Add files via upload --- __init__.py | 3 +++ auto_download.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 2 ++ 3 files changed, 50 insertions(+) create mode 100644 __init__.py create mode 100644 auto_download.py create mode 100644 requirements.txt diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..edae22b --- /dev/null +++ b/__init__.py @@ -0,0 +1,3 @@ +from .auto_download import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS +WEB_DIRECTORY = "./web" +__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS", "WEB_DIRECTORY"] \ No newline at end of file diff --git a/auto_download.py b/auto_download.py new file mode 100644 index 0000000..b32633d --- /dev/null +++ b/auto_download.py @@ -0,0 +1,45 @@ +import torch +import numpy as np +from PIL import Image +import io +import base64 +from server import PromptServer + +class AutoDownloadNode: + def __init__(self): + pass + + @classmethod + def INPUT_TYPES(s): + return { + "required": { + "image": ("IMAGE",), + "filename_prefix": ("STRING", {"default": "ComfyUI2Client"}) + } + } + + RETURN_TYPES = () + FUNCTION = "transmit_to_client" + OUTPUT_NODE = True + CATEGORY = "custom_nodes/Image" + + def transmit_to_client(self, image, filename_prefix): + ui_images = [] + for index, img_tensor in enumerate(image): + i = 255. * img_tensor.cpu().numpy() + img = Image.fromarray(np.clip(i, 0, 255).astype(np.uint8)) + + buffer = io.BytesIO() + img.save(buffer, format="PNG") + img_bytes = buffer.getvalue() + img_base64 = base64.b64encode(img_bytes).decode('utf-8') + + PromptServer.instance.send_sync("auto_download_direct", { + "data": img_base64, + "filename": f"{filename_prefix}_{index:05d}.png" + }) + + return {"ui": {"images": []}} + +NODE_CLASS_MAPPINGS = {"AutoDownloadNode": AutoDownloadNode} +NODE_DISPLAY_NAME_MAPPINGS = {"AutoDownloadNode": "AutoDownload2Client"} \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..a9a1a25 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +numpy +Pillow \ No newline at end of file