From 3ad6de7ce4306700e2dd2b7400fd57d5d253c37b Mon Sep 17 00:00:00 2001 From: atmaranto <35581227+atmaranto@users.noreply.github.com> Date: Thu, 7 Mar 2024 04:09:07 -0600 Subject: [PATCH] Updated README and comments --- README.md | 8 ++++++-- comfyui_to_python.py | 11 +++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 3e7ddce..a3d4ef3 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ## ComfyUI-to-Python-Extension (SaveAsScript version) -This is a fork of the [ComfyUI-To-Python-Extension](https://github.com/pydn/ComfyUI-to-Python-Extension) by Peyton DeNiro. It provides a more robust command-line interface and the ability to export your current workflow as a script directly from the ComfyUI web interface. +This is a fork maintained by Anthony Maranto of the original [ComfyUI-To-Python-Extension](https://github.com/pydn/ComfyUI-to-Python-Extension) by Peyton DeNiro. It provides a more robust command-line interface and the ability to export your current workflow as a script directly from the ComfyUI web interface. ### Usage (Web) @@ -8,7 +8,7 @@ Upon installation, there will be a button labeled "Save as Script" on the interf ![A button that exports the current script on the ComfyUI](images/save_as_script.png) -Click that button and enter your preferred name for the downloaded script (no ".py" is appeneded automatically), and your file will be downloaded. +Click that button and enter your preferred name for the downloaded script (extension not added automatically), and your file will be downloaded. Note that if you use the script this way, you do **not** need to enable developer mode. You *will* if you use the CLI (to get the API JSON). @@ -33,6 +33,10 @@ options: Overwrite the output file if it exists ``` +### Other Changes + +I also fixed what seemed to be a minor bug with exporting certain Crystools nodes, possibly due to their unusual name. + ## Original Description The `ComfyUI-to-Python-Extension` is a powerful tool that translates [ComfyUI](https://github.com/comfyanonymous/ComfyUI) workflows 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. diff --git a/comfyui_to_python.py b/comfyui_to_python.py index 47ae90e..a172bbd 100644 --- a/comfyui_to_python.py +++ b/comfyui_to_python.py @@ -400,12 +400,12 @@ class ComfyUItoPython: """ def __init__(self, workflow: str = "", input_file: str = "", output_file: (str | TextIO) = "", queue_size: int = 10, node_class_mappings: Dict = NODE_CLASS_MAPPINGS): - """Initialize the ComfyUItoPython class with the given parameters. + """Initialize the ComfyUItoPython class with the given parameters. Exactly one of workflow or input_file must be specified. Args: - workflow (str): The + workflow (str): The workflow's JSON. input_file (str): Path to the input JSON file. - output_file (str): Path to the output Python file. + output_file (str | TextIO): Path to the output file or a file-like object. queue_size (int): The number of times a workflow will be executed by the script. Defaults to 10. node_class_mappings (Dict): Mappings of node classes. Defaults to NODE_CLASS_MAPPINGS. """ @@ -414,6 +414,9 @@ class ComfyUItoPython: elif not input_file and not workflow: raise ValueError("Needs input_file or workflow") + if not output_file: + raise ValueError("Needs output_file") + self.workflow = workflow self.input_file = input_file self.output_file = output_file @@ -430,7 +433,7 @@ class ComfyUItoPython: None """ #if self.should_init_custom_nodes: - # Step 1: Import all custom nodes (already done for us) + # Step 1: Import all custom nodes (already done for us in this fork) #import_custom_nodes() # Step 2: Read JSON data from the input file