diff --git a/ComfyUI-to-Python-Extension/__init__.py b/ComfyUI-to-Python-Extension/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/README.md b/README.md index 3fe33f9..c2d1c11 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ## Overview -The `ComfyUI-to-Python-Extension` is a powerful tool that translates ComfyUI workflow into executable Python code. Designed to bridge the gap between ComfyUI's visual interface and Python's programming environment, this script facilitates the seamless transition from design to code execution. Whether you're a data scientist, a software developer, or an AI enthusiast, this tool streamlines the process of implementing ComfyUI workflows in Python. The output makes it easy to queue a large amount of images for generation and provides a base script to easily modify for experimination. +The `ComfyUI-to-Python-Extension` is a powerful tool that translates the ComfyUI workflow into executable Python code. Designed to bridge the gap between ComfyUI's visual interface and Python's programming environment, this script facilitates the seamless transition from design to code execution. Whether you're a data scientist, a software developer, or an AI enthusiast, this tool streamlines the process of implementing ComfyUI workflows in Python. The output makes it easy to queue a large amount of images for generation and provides a base script to easily modify for experimination. **Convert this:** @@ -14,12 +14,14 @@ import random import sys sys.path.append("../") -from nodes import KSamplerAdvanced -from nodes import EmptyLatentImage -from nodes import VAEDecodeTiled -from nodes import SaveImage -from nodes import CheckpointLoaderSimple -from nodes import CLIPTextEncode +from nodes import ( + KSamplerAdvanced, + EmptyLatentImage, + VAEDecodeTiled, + SaveImage, + CLIPTextEncode, + CheckpointLoaderSimple, +) def main(): diff --git a/ComfyUI-to-Python-Extension/generate_python_code.py b/comfyui_to_python.py similarity index 99% rename from ComfyUI-to-Python-Extension/generate_python_code.py rename to comfyui_to_python.py index d53c8f9..3c9d5dd 100644 --- a/ComfyUI-to-Python-Extension/generate_python_code.py +++ b/comfyui_to_python.py @@ -3,14 +3,16 @@ import inspect import json import logging import os -from typing import Dict, List, Any, Callable import sys +import black + +from typing import Dict, List, Any, Callable + sys.path.append('../') from nodes import NODE_CLASS_MAPPINGS -import black logging.basicConfig(level=logging.INFO) @@ -218,7 +220,7 @@ def assemble_python_code(import_statements: set, loader_code: List[str], code: L final_code (str): Generated final code as a string """ static_imports = ['import random'] - imports_code = [f"from nodes import {class_name}" for class_name in import_statements] + imports_code = [f"from nodes import {', '.join([class_name for class_name in import_statements])}" ] main_function_code = f"def main():\n\t" + '\n\t'.join(loader_code) + f'\n\n\tfor q in {range(1, queue_size)}:\n\t' + '\n\t'.join(code) final_code = '\n'.join(static_imports + ['import sys\nsys.path.append("../")'] + imports_code + ['', main_function_code, '', 'if __name__ == "__main__":', '\tmain()']) final_code = black.format_str(final_code, mode=black.Mode()) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..5bb9376 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,13 @@ +torch +torchdiffeq +torchsde +einops +transformers>=4.25.1 +safetensors>=0.3.0 +aiohttp +accelerate +pyyaml +Pillow +scipy +tqdm +black \ No newline at end of file