Skip to content

Commit cc30008

Browse files
docs: add Comfy-Cli and Modal example (#68, #69)
Co-Authored-By: the-dream-machine <[email protected]>
1 parent eebfaae commit cc30008

File tree

3 files changed

+94
-5
lines changed

3 files changed

+94
-5
lines changed

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,18 @@ It has the following use cases:
4848

4949
## Installation
5050
### With ComfyUI
51-
Install [ComfyUI](https://github.com/comfyanonymous/ComfyUI#installing) first. And then run the following commands:
51+
Install ComfyUI first, see [Installing](https://github.com/comfyanonymous/ComfyUI#installing) or use [Comfy-Cli](https://github.com/Comfy-Org/comfy-cli) to install:
52+
```sh
53+
python -m pip install comfy-cli
54+
comfy --here install
55+
```
56+
And then run the following commands to install ComfyScript:
5257
```sh
5358
cd ComfyUI/custom_nodes
5459
git clone https://github.com/Chaoses-Ib/ComfyScript.git
5560
cd ComfyScript
5661
python -m pip install -e ".[default]"
5762
```
58-
(If you see `ERROR: File "setup.py" or "setup.cfg" not found`, run `python -m pip install -U pip` first.)
5963

6064
Update:
6165
```sh
@@ -64,6 +68,8 @@ git pull
6468
python -m pip install -e ".[default]"
6569
```
6670

71+
`[default]` is necessary to install common dependencies. See [`pyproject.toml`](pyproject.toml) for other options. If no option is specified, ComfyScript will be installed without any dependencies.
72+
6773
### With ComfyUI package
6874
Install [ComfyUI package](https://github.com/hiddenswitch/ComfyUI) first:
6975
- If PyTorch is not installed:
@@ -83,13 +89,14 @@ Install/update ComfyScript:
8389
python -m pip install -U "comfy-script[default]"
8490
```
8591

86-
`[default]` is necessary to install common dependencies. See [`pyproject.toml`](pyproject.toml) for other options. If no option is specified, `comfy-script` will be installed without any dependencies.
87-
8892
If there are problems with the latest ComfyUI package, one can use the last tested version:
8993
```
9094
python -m pip install --no-build-isolation git+https://github.com/hiddenswitch/ComfyUI.git@e8eab4dbc6487a14a0c548a806b0b772e274e3df
9195
```
9296

97+
### Containers
98+
- [Modal](examples/modal.py) by @the-dream-machine (ComfyUI + Comfy-Cli)
99+
93100
### Others
94101
See [troubleshooting](docs/README.md#troubleshooting) if you encountered any problems. To use ComfyScript without installed ComfyUI, see [only ComfyScript package](docs/README.md#only-comfyscript-package) for details. To uninstall, see [uninstallation](docs/README.md#uninstallation).
95102

@@ -164,7 +171,7 @@ with Workflow():
164171
SaveImage(image, 'ComfyUI')
165172
```
166173

167-
A Jupyter Notebook example is available at [`examples/runtime.ipynb`](examples/runtime.ipynb). (Files under `examples` directory will be ignored by Git and you can put your personal notebooks there.)
174+
A Jupyter Notebook example is available at [`examples/runtime.ipynb`](examples/runtime.ipynb).
168175

169176
- [Type stubs](https://typing.readthedocs.io/en/latest/source/stubs.html) will be generated at `comfy_script/runtime/nodes.pyi` after loading. Mainstream code editors (e.g. [VS Code](https://code.visualstudio.com/docs/languages/python)) can use them to help with coding:
170177

docs/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
## Installation
33
See [README](../README.md#installation) for basic ways to install.
44

5+
You can use the following command to install ComfyScript with the latest commit that may has not been released to PyPI yet:
6+
```sh
7+
python -m pip install "comfy-script[default] @ git+https://github.com/Chaoses-Ib/ComfyScript.git"
8+
```
9+
510
### Only ComfyScript package
611
Install/update:
712
```sh

examples/modal.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
'''
2+
An example script for setting up and running ComfyUI and ComfyScript with Modal.
3+
4+
Be careful if you want to replace the official ComfyUI with the comfyui package, Modal does not work well with it: https://github.com/Chaoses-Ib/ComfyScript/issues/69
5+
6+
Author: @the-dream-machine
7+
'''
8+
9+
import subprocess
10+
import modal
11+
12+
image = (
13+
modal.Image.debian_slim(python_version="3.12.5")
14+
.apt_install("git")
15+
.pip_install("comfy-cli==1.1.6")
16+
# use comfy-cli to install the ComfyUI repo and its dependencies
17+
.run_commands("comfy --skip-prompt install --nvidia")
18+
# download all models and custom nodes required in your workflow
19+
.run_commands(
20+
"comfy --skip-prompt model download --url https://civitai.com/api/download/models/290640 --relative-path models/checkpoints"
21+
)
22+
.run_commands(
23+
"cd /root/comfy/ComfyUI/custom_nodes && git clone https://github.com/Chaoses-Ib/ComfyScript.git",
24+
"cd /root/comfy/ComfyUI/custom_nodes/ComfyScript && python -m pip install -e '.[default]'",
25+
)
26+
)
27+
28+
app = modal.App("pony_diffusion_2")
29+
30+
# Optional: serve the UI
31+
@app.function(
32+
allow_concurrent_inputs=10,
33+
concurrency_limit=1,
34+
container_idle_timeout=30,
35+
timeout=1800,
36+
gpu="T4",
37+
)
38+
@modal.web_server(8000, startup_timeout=60)
39+
def ui():
40+
_web_server = subprocess.Popen("comfy launch -- --listen 0.0.0.0 --port 8000", shell=True)
41+
42+
@app.cls(gpu="T4", container_idle_timeout=120, image=image)
43+
class Model:
44+
@modal.build()
45+
def build(self):
46+
print("🛠️ Building container...")
47+
48+
@modal.enter()
49+
def enter(self):
50+
print("✅ Entering container...")
51+
from comfy_script.runtime import load
52+
load()
53+
54+
@modal.exit()
55+
def exit(self):
56+
print("🧨 Exiting container...")
57+
58+
@modal.method()
59+
def generate_image(self, prompt:str):
60+
print("🎨 Generating image...")
61+
from comfy_script.runtime import Workflow
62+
from comfy_script.runtime.nodes import CheckpointLoaderSimple, CLIPTextEncode, EmptyLatentImage, KSampler, VAEDecode, SaveImage, CivitAICheckpointLoader
63+
64+
with Workflow(wait=True):
65+
model, clip, vae = CivitAICheckpointLoader('https://civitai.com/models/101055?modelVersionId=128078')
66+
# model, clip, vae = CheckpointLoaderSimple("ponyDiffusionV6XL_v6StartWithThisOne.safetensors")
67+
conditioning = CLIPTextEncode('beautiful scenery nature glass bottle landscape, , purple galaxy bottle,', clip)
68+
conditioning2 = CLIPTextEncode('text, watermark', clip)
69+
latent = EmptyLatentImage(512, 512, 1)
70+
latent = KSampler(model, 156680208700286, 20, 8, 'euler', 'normal', conditioning, conditioning2, latent, 1)
71+
image = VAEDecode(latent, vae)
72+
result = SaveImage(image, 'ComfyUI')
73+
print("result", result)
74+
75+
@app.local_entrypoint()
76+
def main(prompt: str):
77+
Model().generate_image.remote(prompt)

0 commit comments

Comments
 (0)