-
Notifications
You must be signed in to change notification settings - Fork 2
/
README.md.jinja2
315 lines (239 loc) · 13.2 KB
/
README.md.jinja2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
<!-- Note: This file is a jinja2 template of a Markdown file. -->
<!--
{% set last_unstable_release=shell('tomlq -r \'.["tool"]["comfy-catapult-project-metadata"]["last_unstable_release"]\' pyproject.toml',
include_args=False) | trim %}
{% set last_stable_release=shell('tomlq -r \'.["tool"]["comfy-catapult-project-metadata"]["last_stable_release"]\' pyproject.toml',
include_args=False) | trim %}
-->
# README
**Warning:** Very raw and unmaintained code. Use at your own risk. Mainly
intended as a starting point.
![Top language][19] ![GitHub License][11] [![PyPI - Version][12]][13]
[![Python Version][18]][13]
| Branch | Build Status | |
| ------- | ------------------------- | -------------------------------------------- |
| Master | [![Build and Test][1]][2] | [![since tagged][14]][20] ![last commit][16] |
| Develop | [![Build and Test][3]][4] | [![since tagged][15]][21] ![last commit][17] |
```
ComfyUI API Endpoint <| <= Comfy Catapult <=> HTTP Server <| <= Public users
<| <|
<| Your python program <| Your Webui/JS frontend
<| <|
<| Your workflows <|
<| Your HTTP server <|
```
## What is it?
Comfy Catapult is a library for scheduling and running ComfyUI workflows from a
Python program, via the existing API endpoint. ComfyUI typically works by
hosting this API endpoint for its user interface.
This makes it easier for you to make workflows via the UI, and then use it from
a program.
### Scheduling a job
From
[`{{ path('comfy_catapult/catapult_base.py') }}`](comfy_catapult/catapult_base.py):
`{{ pysignature('comfy_catapult/catapult_base.py', symbol='ComfyCatapultBase.Catapult', backtickify='py') }}`
From
[`{{ path('examples/sdxlturbo_example_catapulter.py') }}`](examples/sdxlturbo_example_catapulter.py):
`{{ pysnippet('examples/sdxlturbo_example_catapulter.py', symbol='ExampleWorkflowInfo', backtickify='py') }}`
`{{ pysnippet('examples/sdxlturbo_example_catapulter.py', symbol='RunExampleWorkflow', backtickify='py') }}`
## Related Projects
| Project | ComfyUI API Wrapper | Outsource Backend | Distribute Execution | Wrap Workflow | Studio |
| -------------------------------- | ------------------- | ----------------- | -------------------- | ------------- | ------ |
| [CushyStudio][2] | ? | ? | ? | ? | Yes |
| [ComfyUI-Serving-Toolkit][3] | X | ? | ? | Yes | ? |
| [ComfyUI_NetDist][4] | X | ? | Yes | ? | ? |
| [ComfyUI script_examples][1] | Yes | No | No | No | No |
| [comfyui-python-api][5] | ? | ? | ? | Yes | ? |
| [comfyui-deploy][6] | ? | ? | ? | Yes | ? |
| [ComfyUI-to-Python-Extension][7] | ? | ? | ? | Yes | ? |
| [ComfyScript][8] | ? | ? | ? | Yes | ? |
| [hordelib][9] | ? | Yes | ? | ? | ? |
| [comfyui-cloud][10] | ? | Yes | ? | ? | ? |
**Outsource compute:**
## Getting Started
### Exporting workflows in the API json format
In ComfyUI web interface:
1. Open settings (gear box in the corner).
2. Enable the ability to export in the API format, `Enable Dev mode Options`.
3. Click new menu item `Save (API format)`.
![ComfyUI API format export instructions](assets/comfy-export-instructions.png)
### Example workflow: Prepare ComfyUI
**If you don't want to try the example workflow, you can skip this section.**
You need to get `sd_xl_turbo_1.0_fp16.safetensors` into the ComfyUI model
directory.
Hugging Face page:
[huggingface.co/stabilityai/sdxl-turbo/blob/main/sd_xl_turbo_1.0_fp16.safetensors](https://huggingface.co/stabilityai/sdxl-turbo/blob/main/sd_xl_turbo_1.0_fp16.safetensors).
Direct download link:
[huggingface.co/stabilityai/sdxl-turbo/resolve/main/sd_xl_turbo_1.0_fp16.safetensors](huggingface.co/stabilityai/sdxl-turbo/resolve/main/sd_xl_turbo_1.0_fp16.safetensors).
### Download the example workflow, and export it in the API format
**This is optional, you can use the example workflow in `test_data/` instead and
skip this step.**
```bash
# Download the workflow:
wget https://github.com/comfyanonymous/ComfyUI_examples/raw/master/sdturbo/sdxlturbo_example.png
# 1. Open the Workflow in ComfyUI and export it. AFAIK there isn't a nice way
# to automated this right now.
#
# 2, Save to `./sdxlturbo_example_api.json`.
#
# Or just use `test_data/sdxlturbo_example_api.json`.
```
### Install as a library and run the examples
```bash
# Inside your environment:
pip install comfy-catapult
# If you set this environment variable, you don't have to specify it as an
# argument.
export COMFY_API_URL=http://127.0.0.1:8188
# Note, in WSL2 you may have to use the IP of the host to connect to ComfyUI.
python -m comfy_catapult.examples.sdxlturbo_example_catapulter \
--api_workflow_json_path "$PWD/sdxlturbo_example_api.json" \
--tmp_path "$PWD/.deleteme/tmp/" \
--output_path "$PWD/.deleteme/output.png" \
--positive_prompt "amazing cloudscape, towering clouds, thunderstorm, awe" \
--negative_prompt "dull, blurry, nsfw"
# Optional if you don't want to set the environment variable:
# --comfy_api_url "..."
# Done! Now $PWD/.deleteme/output.png should contain the output image.
# Some other examples:
python -m comfy_catapult.examples.add_a_node
python -m comfy_catapult.examples.using_pydantic
```
- Examine
[`examples/sdxlturbo_example_catapulter.py`](examples/sdxlturbo_example_catapulter.py)
to see how to use the main `ComfyCatapult` library.
- Examine
[`test_data/sdxlturbo_example_api.json`](test_data/sdxlturbo_example_api.json)
to see the API format. This will be necessary in order to programmatically set
the proper inputs for the workflow.
- (Optional) See [`examples/using_pydantic.py`](examples/using_pydantic.py)
for how to parse the API format into the Pydantic models schema for easier
navigation.
- (Optional) See [`examples/add_a_node.py`](examples/add_a_node.py) for how to
add a new node to a workflow. This is useful when you need to add nodes at
runtime (such as adding a bunch of LoadImage nodes).
- See [`comfy_catapult/catapult_base.py`](comfy_catapult/catapult_base.py) for
the main library interface.
- (Optional) See [`comfy_catapult/catapult.py`](comfy_catapult/catapult_base.py)
for the main library implementation.
- (Optional) See
[`comfy_catapult/api_client_base.py`](comfy_catapult/api_client_base.py) for
the direct ComfyUI API endpoint client library interface; you don't need to
use this usually.
- (Optional) For those who want to do use the raw API themselves and learn how
it works: Examine
[`comfy_catapult/api_client.py`](comfy_catapult/api_client.py) to see the API
client implementation if you want to directly interface with ComfyUI endpoints
yourself.
- (Optional) Also see
[ComfyUI/server.py](https://github.com/comfyanonymous/ComfyUI/blob/977eda19a6471fbff253dc92c3c2f1a4a67b1793/server.py#L99)
(pinned to a specific commit) for the server `@routes` endpoint
implementations.
### Development; install dependencies and run the examples
This is if you are intending on contributing or altering the library itself.
```bash
git clone https://github.com/realazthat/comfy-catapult.git
cd comfy-catapult
pip install -r requirements.txt
# Run the example workflow:
PYTHONPATH=$PYTHONPATH:$PWD python examples/sdxlturbo_example_catapulter.py \
--api_workflow_json_path "$PWD/sdxlturbo_example_api.json"
--tmp_path "$PWD/.deleteme/tmp/" \
--output_path "$PWD/.deleteme/output.png" \
--positive_prompt "amazing cloudscape, towering clouds, thunderstorm, awe" \
--negative_prompt "dull, blurry, nsfw"
```
### Parsing the API format into the Pydantic models schema for easier navigation
From [`{{ path('examples/using_pydantic.py') }}`](examples/using_pydantic.py):
`{{ snippet('examples/using_pydantic.py', start='SNIPPETSTART', end='SNIPPETEND', backtickify='py') }}`
### Adding a new node to a workflow
From [`{{ path('examples/add_a_node.py') }}`](examples/add_a_node.py):
`{{ snippet('examples/add_a_node.py', start='# SNIPPETSTART', end='# SNIPPETEND', backtickify='py') }}`
## Requirements
- Python 3.10+
- ComfyUI server with API endpoint enabled.
### Known to work on
- **Python 3.10.0**, WSL2/Windows11, Ubuntu 22.04.2 LTS
- **Python 3.10.0**, Ubuntu 22.04
## Limitations
- ETA estimator isn't working
## TODO
- [ ] Helpers should support remote/cloud storage for ComfyUI input/output/model
directories (Currently only supports local paths).
- [ ] ETA Estimator.
- [ ] Make sure the schema can parse the formats even if the format adds new
fields.
## Contributions
### Development environment: Linux-like
- For running `pre.sh` (Linux-like environment).
- Requires `pyenv`, or an exact matching version of python as in
[`{{path('.python-version')}}`](./.python-version).
- `jq`, ([installation](https://jqlang.github.io/jq/)) required for
[yq](https://github.com/kislyuk/yq), which is itself required for our
`{{path('README.md')}}` generation, which uses `tomlq` (from the
[yq](https://github.com/kislyuk/yq) package) to include version strings from
`{{path('pyproject.toml')}}`.
- `bash`, `grep`, `awk`, `sed` `xxd`, `git`, `xxhash` (for tests/workflows).
- Requires nodejs (for act).
- Requires Go (to run act).
- docker (for act).
### Commit Process
1. (Optionally) Fork the `develop` branch.
2. Stage your files: `git add path/to/file.py`.
3. `bash scripts/pre.sh`, this will format, lint, and test the code.
4. `git status` check if anything changed (generated `{{path('README.md')}}` for
example), if so, `git add` the changes, and go back to the previous step.
5. `git commit -m "..."`.
6. Make a PR to `develop` (or push to develop if you have the rights).
## Release Process
These instructions are for maintainers of the project.
1. `develop` branch: Run `bash {{path('scripts/pre.sh')}}` to ensure everything
is in order.
2. `develop` branch: Bump the version in `{{path('pyproject.toml')}}`, following
semantic versioning principles. Also modify the `last_unstable_release` and
`last_stable_release` in the `[tool.comfy-catapult-project-metadata]` table
as appropriate.
3. `develop` branch: Commit these changes with a message like "Prepare release
X.Y.Z". (See the contributions section [above](#commit-process)).
4. `master` branch: Merge the `develop` branch into the `master` branch:
`git checkout master && git merge develop --no-ff`.
5. `master` branch: Tag the release: Create a git tag for the release with
`git tag -a vX.Y.Z -m "Version X.Y.Z"`.
6. Publish to PyPI: Publish the release to PyPI with
`bash scripts/deploy-to-pypi.sh`.
7. Push to GitHub: Push the commit and tags to GitHub with `git push` and
`git push --tags`.
8. `git checkout develop && git merge master` The `--no-ff` option adds a commit
to the master branch for the merge, so refork the develop branch from the
master branch.
[1]:
https://github.com/realazthat/comfy-catapult/actions/workflows/build-and-test.yml/badge.svg?branch=master
[2]:
https://github.com/realazthat/comfy-catapult/actions/workflows/build-and-test.yml
[3]:
https://github.com/realazthat/comfy-catapult/actions/workflows/build-and-test.yml/badge.svg?branch=develop
[4]:
https://github.com/realazthat/comfy-catapult/actions/workflows/build-and-test.yml
[5]: https://github.com/andreyryabtsev/comfyui-python-api
[6]: https://github.com/BennyKok/comfyui-deploy
[7]: https://github.com/pydn/ComfyUI-to-Python-Extension
[8]: https://github.com/Chaoses-Ib/ComfyScript
[9]: https://pypi.org/project/hordelib/
[10]: https://github.com/nathannlu/comfyui-cloud
[11]: https://img.shields.io/github/license/realazthat/comfy-catapult
[12]: https://img.shields.io/pypi/v/comfy-catapult
[13]: https://pypi.org/project/comfy-catapult/
[14]:
https://img.shields.io/github/commits-since/realazthat/comfy-catapult/v{{last_stable_release}}/master
[15]:
https://img.shields.io/github/commits-since/realazthat/comfy-catapult/v{{last_stable_release}}/develop
[16]: https://img.shields.io/github/last-commit/realazthat/comfy-catapult/master
[17]:
https://img.shields.io/github/last-commit/realazthat/comfy-catapult/develop
[18]: https://img.shields.io/pypi/pyversions/comfy-catapult
[19]:
https://img.shields.io/github/languages/top/realazthat/comfy-catapult.svg?&cacheSeconds=28800
[20]:
https://github.com/realazthat/comfy-catapult/compare/v{{last_stable_release}}...master
[21]:
https://github.com/realazthat/comfy-catapult/compare/v{{last_stable_release}}...develop