comfyanonymous / ComfyUI

The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface.
https://www.comfy.org/
GNU General Public License v3.0
52.62k stars 5.56k forks source link

Need API Document #1037

Open huangyous opened 1 year ago

huangyous commented 1 year ago

I found these API keywords in server.py.Would you add some use case of these? BTW 1.the API "/prompt" will generate pic file in the output folder,is there a method to delete the file after I download the file? BTW 2.When I use img2img with API,I have to upload image file to input folder first.Do I have to write my own file uploader program?

@routes.get('/ws') @routes.get("/") @routes.get("/embeddings") @routes.get("/extensions") @routes.post("/upload/image") @routes.post("/upload/mask") @routes.get("/view") @routes.get("/view_metadata/{folder_name}") @routes.get("/system_stats") @routes.get("/prompt") @routes.get("/object_info") @routes.get("/object_info/{node_class}") @routes.get("/history") @routes.get("/history/{prompt_id}") @routes.get("/queue") @routes.post("/prompt") @routes.post("/queue") @routes.post("/interrupt") @routes.post("/history")

dotgrid commented 1 year ago

See this discussion for some example use cases and sample scripts using the API.

I'm not aware of any further API documentation (beyond the links in that thread). However, I've been able to work with the API and have it running smoothly alongside a Ruby on Rails app. It's possible! 🙂

dotgrid commented 1 year ago

To address your specific questions:

  1. You'll need to manage file deletion on the ComfyUI server. By integrating Comfy, as shown in the example API script, you'll receive the images via the API upon completion. I store these images alongside my web server. Additionally, I run a cron job on the Comfy server to delete all output images each night.
  2. You'll have to make the image inputs accessible to Comfy. This could involve an upload process, or you might set up a shared folder that both your server and the Comfy server can access. The approach will depend on your particular setup.

I hope this information is helpful!

huangyous commented 1 year ago

thanks for replying,I found this "@routes.post("/upload/image")" in server.py,so I think ComfyUI can handler file uploading itself,but I can't find any usage example

ltdrdata commented 1 year ago

thanks for replying,I found this "@routes.post("/upload/image")" in server.py,so I think ComfyUI can handler file uploading itself,but I can't find any usage example

You can see usage of them in .js files under /ComfyUI/web/...

dotgrid commented 1 year ago

@huangyous Great find - that's helpful to know!

huangyous commented 1 year ago

thanks for replying,I found this "@routes.post("/upload/image")" in server.py,so I think ComfyUI can handler file uploading itself,but I can't find any usage example

You can see usage of them in .js files under /ComfyUI/web/...

thanks

wcurti commented 1 year ago

Just following up on this, is there any way to use the API to poll for the progress percentage?

-edit-

Stupid question. Ignore me.

pydn commented 1 year ago

Sounds like you all have made progress in working with the API, but thought I'd share that I created an extension to convert any comfyui workflow (including custom nodes) into executable python code that will run without relying on the comfyui server.

If you are comfortable in Python, it may be more straightforward to use than the API. If interested, check it out here: https://github.com/pydn/ComfyUI-to-Python-Extension

olegchomp commented 1 year ago

Just following up on this, is there any way to use the API to poll for the progress percentage?

-edit-

Stupid question. Ignore me.

how you get progress info in API?

wcurti commented 1 year ago

If you're using the websocket it's transmitted automatically when you recv. In the websocket example, add a "print(str(out))" after the recv and you'll see everything it sends.

olegchomp commented 1 year ago

If you're using the websocket it's transmitted automatically when you recv. In the websocket example, add a "print(str(out))" after the recv and you'll see everything it sends.

thank you!

yuhuihu commented 1 year ago

Sounds like you all have made progress in working with the API, but thought I'd share that I created an extension to convert any comfyui workflow (including custom nodes) into executable python code that will run without relying on the comfyui server.

If you are comfortable in Python, it may be more straightforward to use than the API. If interested, check it out here: https://github.com/pydn/ComfyUI-to-Python-Extension

really nice work. If the official of ComfyUI can merge it, it would be better. Although this feature maybe divergent to the core features.

Yash-Patidar commented 1 year ago

Could anyone help me to use the @routes.post("/upload/image") API?

gozuslayer commented 9 months ago

@Yash-Patidar just in case you still need to post an image to that route, here is my python code:

data = {"subfolder": "your_subfolder"}
files = {'image': (the_file_name_on_server_you_want, open(image_path, 'rb'))}
resp = requests.post("http://127.0.0.1:8188/upload/image", files=files, data=data)
print(resp.content)
Phando commented 8 months ago

In the upload/mask endpoint what is the originalRef payload supposed to look like?

yuhuihu commented 8 months ago

@Yash-Patidar just in case you still need to post an image to that route, here is my python code:

data = {"subfolder": "your_subfolder"}
files = {'image': (the_file_name_on_server_you_want, open(image_path, 'rb'))}
resp = requests.post("http://127.0.0.1:8188/upload/image", files=files, data=data)
print(resp.content)

saved me from urllib 's error of default method. Thank you