Skip to content

Commit 8f0a473

Browse files
committed
Update README, add template args
1 parent 0b4788d commit 8f0a473

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,19 @@ For instance, if you have a simple default workflow, but have converted the text
4848
4949
Then the unfilled required variable will be available as an argument:
5050
```bash
51-
usage: default-workflow.py [-h] text1
51+
usage: workflow.py [-h] [--queue-size QUEUE_SIZE] [--comfyui-directory COMFYUI_DIRECTORY] filename_prefix1
5252
53-
A converted ComfyUI workflow. Required inputs listed below. Values passed should be in JSON
53+
A converted ComfyUI workflow. Required inputs listed below. Values passed should be valid JSON (assumes string if not valid JSON).
5454
5555
positional arguments:
56-
text1 Argument 0, input `text` for node "CLIP Text Encode (Prompt)" id 6 (autogenerated)
56+
filename_prefix1 Argument 1, input `filename_prefix` for node "Save Image" id 64 (autogenerated)
5757
5858
options:
59-
-h, --help show this help message and exit
59+
-h, --help show this help message and exit
60+
--queue-size QUEUE_SIZE, -q QUEUE_SIZE
61+
How many times the workflow will be executed (default: 10)
62+
--comfyui-directory COMFYUI_DIRECTORY, -c COMFYUI_DIRECTORY
63+
Where to look for ComfyUI (default: current directory)
6064
```
6165
6266
Arguments are new. **If you have any suggestions on how to improve them or on how to effectively specify defaults in the workflow and override in the command-line**, feel free to suggest that in an Issue.

comfyui_to_python.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -306,12 +306,12 @@ def assemble_python_code(self, import_statements: set, speical_functions_code: L
306306
for func in [get_value_at_index, find_path, add_comfyui_directory_to_sys_path, add_extra_model_paths, import_custom_nodes, parse_arg]:
307307
func_strings.append(f'\n{inspect.getsource(func)}')
308308

309-
argparse_code = ""
310-
if arg_inputs:
311-
argparse_code = f'\nparser = argparse.ArgumentParser(description="A converted ComfyUI workflow. Required inputs listed below. Values passed should be in JSON")\n'
312-
for i, (input_name, arg_desc) in enumerate(arg_inputs):
313-
argparse_code += f'parser.add_argument("{input_name}", help="{arg_desc} (autogenerated)")\n'
314-
argparse_code += 'args = parser.parse_args()\nsys.argv = [sys.argv[0]]\n'
309+
argparse_code = f'\nparser = argparse.ArgumentParser(description="A converted ComfyUI workflow. Required inputs listed below. Values passed should be valid JSON (assumes string if not valid JSON).")\n'
310+
for i, (input_name, arg_desc) in enumerate(arg_inputs):
311+
argparse_code += f'parser.add_argument("{input_name}", help="{arg_desc} (autogenerated)")\n'
312+
argparse_code += f'parser.add_argument("--queue-size", "-q", type=int, default={queue_size}, help="How many times the workflow will be executed (default: {queue_size})")\n'
313+
argparse_code += f'parser.add_argument("--comfyui-directory", "-c", default=None, help="Where to look for ComfyUI (default: current directory)")\n'
314+
argparse_code += 'args = parser.parse_args()\nsys.argv = [sys.argv[0]]\n'
315315

316316
# Define static import statements required for the script
317317
static_imports = ['import os', 'import random', 'import sys', 'import json', 'import argparse', 'from typing import Sequence, Mapping, Any, Union',
@@ -327,7 +327,7 @@ def assemble_python_code(self, import_statements: set, speical_functions_code: L
327327
imports_code = [f"from nodes import {', '.join([class_name for class_name in import_statements])}", '']
328328
# Assemble the main function code, including custom nodes if applicable
329329
main_function_code = "def main():\n\t" + f'{custom_nodes}with torch.inference_mode():\n\t\t' + '\n\t\t'.join(speical_functions_code) \
330-
+ f'\n\n\t\tfor q in range({queue_size}):\n\t\t' + '\n\t\t'.join(code)
330+
+ f'\n\n\t\tfor q in range(args.queue_size):\n\t\t' + '\n\t\t'.join(code)
331331
# Concatenate all parts to form the final code
332332
final_code = '\n'.join(static_imports + imports_code + [main_function_code, '', 'if __name__ == "__main__":', '\tmain()'])
333333
# Format the final code according to PEP 8 using the Black library

comfyui_to_python_utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
sys.path.append('../')
66

7+
args = None
78

89
def import_custom_nodes() -> None:
910
"""Find all custom nodes in the custom_nodes folder and add those node objects to NODE_CLASS_MAPPINGS
@@ -35,7 +36,10 @@ def find_path(name: str, path: str = None) -> str:
3536
"""
3637
# If no path is given, use the current working directory
3738
if path is None:
38-
path = os.getcwd()
39+
if args is None or args.comfyui_directory is None:
40+
path = os.getcwd()
41+
else:
42+
path = args.comfyui_directory
3943

4044
# Check if the current directory contains the name
4145
if name in os.listdir(path):

0 commit comments

Comments
 (0)