You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+41-1Lines changed: 41 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,31 @@ I plan to do some fresh install testing when I have time.
6
6
7
7
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.
8
8
9
+
Once exported, this script can be run to run the workflow without a frontend, or it can be imported and the `main()` function can be used to call the workflow programatically.
10
+
11
+
### New Feauture: Module Support
12
+
13
+
Now, scripts exported with SaS can be imported as modules! Once you have a script exported, you can use it like:
14
+
```python
15
+
>>>import exported_script
16
+
>>> results = exported_script.main("A prompt that would be sent to the command-line arguments", queue_size=1)
17
+
```
18
+
19
+
The first `SaveImage` node reached will instead *return* the output to the calling function.
20
+
21
+
### New Feature: Custom Output Path
22
+
23
+
When running the exported script normally, you can now specify an `--output` option that will override the default path of `SaveImage` nodes.
24
+
If only a single image is exported by the node, then the path will be used verbatim. Otherwise, the path will be used as a prefix, and `_#####.png` will be appended
25
+
to ensure uniqueness. Note that files *will be clobbered* if only one image is exported.
26
+
If the path is a directory, the `SaveImage` node's `filename_prefix` will be used.
27
+
28
+
If `-` is selected as the output path, normal ComfyUI output will be piped to stderr and the resultant image will be piped to stdout, allowing one to use the script
29
+
like:
30
+
```bash
31
+
python3 script.py "A painting of outer space" --output - --queue-size 1 > image.png
32
+
```
33
+
9
34
### Usage (Web)
10
35
11
36
Upon installation, there will be a button labeled "Save as Script" on the interface, pictured below:
@@ -58,19 +83,34 @@ positional arguments:
58
83
options:
59
84
-h, --help show this help message and exit
60
85
--queue-size QUEUE_SIZE, -q QUEUE_SIZE
61
-
How many times the workflow will be executed (default: 10)
86
+
How many times the workflow will be executed (default: 1)
Where to look for ComfyUI (default: current directory)
89
+
--output OUTPUT, -o OUTPUT
90
+
The location to save the output image. Either a file path, a directory, or - for stdout (default: the ComfyUI output directory)
91
+
--disable-metadata Disables writing workflow metadata to the outputs
64
92
```
65
93
66
94
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.
67
95
96
+
#### Passing Arguments to ComfyUI
97
+
98
+
In case you want to pass anything to the ComfyUI server as an argument, you can use `--` to indicate you're done with SaS arguments and are now passing ComfyUI arguments.
99
+
For instance:
100
+
101
+
```bash
102
+
python3 script.py "A painting of outer space" --queue-size 1 -- --cpu
103
+
```
104
+
68
105
### Other Changes
69
106
70
107
#### Bugfixes
71
108
- Windows paths are now properly escaped.
72
109
- I also fixed what seemed to be a minor bug with exporting certain Crystools nodes, possibly due to their unusual name.
73
110
111
+
#### TODO
112
+
- Improve compatibility with module API
113
+
74
114
## Old Description of ComfyUI-to-Python-Extension (usage altered)
75
115
76
116
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.
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'
325
-
argparse_code+=f'parser.add_argument("--comfyui-directory", "-c", default=None, help="Where to look for ComfyUI (default: current directory)")\n'
326
-
argparse_code+=f'parser.add_argument("--output", "-o", default=None, help="The location to save the output image -- a file path, a directory, or - for stdout (default: the ComfyUI output directory)")\n'
327
-
argparse_code+=f'parser.add_argument("--disable-metadata", action="store_true", help="Disables writing workflow metadata to the outputs")\n'
argparse_code.append(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')
329
+
argparse_code.append('parser.add_argument("--comfyui-directory", "-c", default=None, help="Where to look for ComfyUI (default: current directory)")\n')
330
+
argparse_code.append(f'parser.add_argument("--output", "-o", default=None, help="The location to save the output image. Either a file path, a directory, or - for stdout (default: the ComfyUI output directory)")\n')
331
+
argparse_code.append(f'parser.add_argument("--disable-metadata", action="store_true", help="Disables writing workflow metadata to the outputs")\n')
332
+
argparse_code.append('''
333
+
comfy_args = [sys.argv[0]]
334
+
if "--" in sys.argv:
335
+
idx = sys.argv.index("--")
336
+
comfy_args += sys.argv[idx+1:]
337
+
sys.argv = sys.argv[:idx]
338
+
339
+
args = None
340
+
if __name__ == "__main__":
341
+
args = parser.parse_args()
342
+
sys.argv = comfy_args
343
+
if args is not None and args.output is not None and args.output == "-":
344
+
ctx = contextlib.redirect_stdout(sys.stderr)
345
+
else:
346
+
ctx = contextlib.nullcontext()
347
+
''')
329
348
330
349
# Define static import statements required for the script
0 commit comments