Skip to content

Commit

Permalink
fix(docs): Modal example return PIL images (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chaoses-Ib committed Oct 3, 2024
1 parent 89cb2fe commit 13957e8
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions examples/modal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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
Author: @the-dream-machine
Authors: @the-dream-machine, @Chaoses-Ib
'''

import subprocess
Expand Down Expand Up @@ -60,8 +60,9 @@ def generate_image(self, prompt:str):
print("🎨 Generating image...")
from comfy_script.runtime import Workflow
from comfy_script.runtime.nodes import CheckpointLoaderSimple, CLIPTextEncode, EmptyLatentImage, KSampler, VAEDecode, SaveImage, CivitAICheckpointLoader
from PIL import Image

with Workflow(wait=True):
with Workflow():
model, clip, vae = CivitAICheckpointLoader('https://civitai.com/models/101055?modelVersionId=128078')
# model, clip, vae = CheckpointLoaderSimple("ponyDiffusionV6XL_v6StartWithThisOne.safetensors")
conditioning = CLIPTextEncode('beautiful scenery nature glass bottle landscape, , purple galaxy bottle,', clip)
Expand All @@ -70,7 +71,8 @@ def generate_image(self, prompt:str):
latent = KSampler(model, 156680208700286, 20, 8, 'euler', 'normal', conditioning, conditioning2, latent, 1)
image = VAEDecode(latent, vae)
result = SaveImage(image, 'ComfyUI')
print("result", result)
images: list[Image.Image] = result.wait().wait()
return images

@app.local_entrypoint()
def main(prompt: str):
Expand Down

4 comments on commit 13957e8

@binarytahr
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请问 Workflow() 不需要设置 wait=True 了吗?一直等到任务完成才退出context。

@Chaoses-Ib
Copy link
Owner Author

@Chaoses-Ib Chaoses-Ib commented on 13957e8 Oct 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@binarytahr 下面 result.wait() 已经等待了

@binarytahr
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

哈哈,原来是这个原因

@binarytahr
Copy link

@binarytahr binarytahr commented on 13957e8 Oct 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我为了方便随时修改 workflow 之后不用重新 modal deploy,拆分成了 client.py 和 server.py 两个文件。
comfyscript 写的 workflow 定义成 function 放在本地 client.py 里面,一开始我把这个 function 作为 argument 传给云端,但是云端会报错获取不到 source code。然后我就把 workflow function 转成 string 后作为 argument 传给云端 server.py。
deploy 好的 server.py 里面用 exec(workflow) 去执行。目前通过读取 output 文件夹里面生成的图片返回 bytes,可以成功运行。
下午试了一下 result.wait().wait(),会报错:NameError: name 'result' is not defined。感觉可能是 exec() 限制比较多,和这个方法不兼容。外面的 result.wait().wait() 获取不到 exec() 里面执行的 result。

Please sign in to comment.