Building a Python API for Comfy UI with Gradio

Поделиться
HTML-код
  • Опубликовано: 26 дек 2024

Комментарии • 109

  • @SanjeevPenupala-7T
    @SanjeevPenupala-7T 5 месяцев назад +2

    Thanks for making this! Extremely clear on how to connect a frontend to ComfyUI.

  • @juan-claudephilander2477
    @juan-claudephilander2477 20 дней назад

    DUde all your videos is very informative. Best Tutorials Online

  • @jeantimex
    @jeantimex 10 месяцев назад

    First time I learn how to use the ComfyUI API, thank you sir!

  • @stevietee3878
    @stevietee3878 10 месяцев назад +1

    This is exactly what I was looking for, thank you for your clear step-by-step help.

    • @CodeCraftersCorner
      @CodeCraftersCorner  10 месяцев назад

      Glad it was helpful, @stevietee3878!

    • @stevietee3878
      @stevietee3878 8 месяцев назад

      @@CodeCraftersCorner hello again, I've made some major breakthroughs with ComfyUI since my first comment, I'm currently developing a workflow to be used in API format with React as front-end for a mobile app, do you have any experience creating UIs with React and are their similar principles involved as the Gradio/Python example you've wonderfully demonstrated ?

    • @CodeCraftersCorner
      @CodeCraftersCorner  8 месяцев назад

      @stevietee3878 No sorry.

  • @mizu-0025
    @mizu-0025 Год назад +3

    Managed to whip up a little Python app, with your help. Thanks!

  • @sirflimflam
    @sirflimflam 10 месяцев назад

    Thanks for this. Been trying to find a low profile but extensible system for accessing my comfy workflows remotely on mobile devices and this method is the one I'm going with. Cheers

  • @EternalAI-v9b
    @EternalAI-v9b 3 месяца назад

    26:29 So STrange! I also got my firest image (in this exact step) CUT and have only a part of it. then next images it gets fixed, but why here we got the same thing?

    • @CodeCraftersCorner
      @CodeCraftersCorner  3 месяца назад +1

      That's is a problem on the Gradio side. Sometimes, the images will not load completely in the browser even with high internet speed. You can replicate the partial image loading bug by trying to load a big image (especially after doing a 4x upscale).

  • @fireguy9931
    @fireguy9931 Год назад +2

    Man I was working on something like this but for the streamlit library. Spot on man instant sub from me 🎉

    • @CodeCraftersCorner
      @CodeCraftersCorner  Год назад

      I am glad you found the video helpful. It's awesome that you are working on something similar with streamlit. Thanks for the sub. If you ever have questions or want to share your progress, feel free to reach out. Happy Coding!

  • @MyDigitalHub
    @MyDigitalHub Год назад +1

    Great job brother

  • @TrungHieuVo-b1u
    @TrungHieuVo-b1u 5 месяцев назад

    Thank you. Your lesson is very clear

  • @RahulYadav-v2i6h
    @RahulYadav-v2i6h Год назад +1

    Thank you so much man, the session was very insightful and I was able to solve what I was intending to do. Good day.

    • @CodeCraftersCorner
      @CodeCraftersCorner  Год назад

      You're very welcome. I'm glad the tutorial was helpful in solving what you intended to do. If you have more questions or topics you'd like me to cover, feel free to let me know. Have a fantastic day!

  • @StringerBell
    @StringerBell 6 месяцев назад

    Your content is AMAZING! You just have a new subscriber! Your presentation skills are really top notch. It's rarely to have someone explain so clearly nowadays.
    I have a workflow that needs to be converted into a Gradio UI, do you work paid gigs?

    • @CodeCraftersCorner
      @CodeCraftersCorner  6 месяцев назад +1

      Thank you very much, @StringerBell! Yes, you can contact me by using this email address to discuss the projects: CodeCraftersCorner@gmail.com

    • @StringerBell
      @StringerBell 6 месяцев назад

      @@CodeCraftersCorner done, I sent you an email

    • @StringerBell
      @StringerBell 6 месяцев назад

      @@CodeCraftersCorner Hey did you happen to receive my email? I sent you the details couple of hours ago but I'm not sure if you received the workflow.

    • @CodeCraftersCorner
      @CodeCraftersCorner  6 месяцев назад

      Yes, i received it and replied back. Thank you.

  • @PEDROMATOSFAST
    @PEDROMATOSFAST 10 месяцев назад

    I love you so macht S2, u are a genius

  • @technicusacity
    @technicusacity 3 месяца назад

    15:22 "seed = -1" not resolve prblm ?

    • @CodeCraftersCorner
      @CodeCraftersCorner  3 месяца назад

      Since the backend is using ComfyUI, this approach does not work. If your backend is Forge or automatic 1111, yes. ComfyUI has a different implementation.

  • @satishgoda
    @satishgoda Год назад +2

    Thank you so much for doing this. Instant subscribe and like!

    • @CodeCraftersCorner
      @CodeCraftersCorner  Год назад

      Thank you for the instant subscribe and like! I am glad the video was helpful. If there is anything specify you like to see in future videos, feel free to let me know. Happy coding!

  • @DeviNatarajan-l7v
    @DeviNatarajan-l7v 24 дня назад

    Thank you so much for the video. It is very useful. I am having one doubt, in real time comfyui server is running in somewhere else, how we can get the outputs from comfyui output directory

    • @CodeCraftersCorner
      @CodeCraftersCorner  24 дня назад

      Thank you for watching! I have made a follow up video on how to use websockets to get the images. This version will keep track of the request ids, allowing for multiple users to use at the same time and correctly sending the output images to the user. You can see this series here: ruclips.net/video/kmZqoLJ2Dhk/видео.html. There's a part 2 and 3 as well.

  • @alecubudulecu
    @alecubudulecu 2 месяца назад

    Thanks so much for this

  • @AmerikaMeraklisi-yr2xe
    @AmerikaMeraklisi-yr2xe 11 месяцев назад +1

    Thank you for this video, I did as you said, It works well but Everytime my models loading in queue prompt process, Cant we pass ? btw I am new in ComfyUI I dont change models I just send prompts.

    • @CodeCraftersCorner
      @CodeCraftersCorner  11 месяцев назад +1

      Thank you for watching, @AmerikaMeraklisi-yr2xe! The model should load once for the first image generation. After that, as long as you do not manually change it and you have enough system RAM, it will stay in memory. Actually, ComfyUI managers the model. The python app just sends the JSON data to ComfyUI. Unfortunately, we cannot just send prompts.

    • @AmerikaMeraklisi-yr2xe
      @AmerikaMeraklisi-yr2xe 11 месяцев назад

      @@CodeCraftersCorner Thank you so much for reply, My another question When we do this on public server for example google colab How can I get image files to my pc, I have to request get but where ?

    • @CodeCraftersCorner
      @CodeCraftersCorner  11 месяцев назад +1

      @AmerikaMeraklisi-yr2xe, Here is a breakdown of the steps:
      1. Create a link or download endpoint. This can be done with a framework like Flask.
      2. You can then get all images from the server's folder.
      3. At this point, you can display them in a user friendly interface and provide a download button for each or simply download all of them.
      If it is a personal project, then you can download the images directly from the Gradio app by right clicking on the image and choose save image. (may be slightly different depending on the browser).
      Gradio also provides a download image button and link. It should be around the top right corner of the output image.

    • @AmerikaMeraklisi-yr2xe
      @AmerikaMeraklisi-yr2xe 11 месяцев назад

      @@CodeCraftersCorner Actually I want to automatıcally download when comfyui finished every que, so download image one by one.

    • @CodeCraftersCorner
      @CodeCraftersCorner  11 месяцев назад +1

      @AmerikaMeraklisi-yr2xe If the Gradio application is running locally on your machine, then you can use the Python Pillow library to save the image to your disk. However, if the app is running on a server, then you will have to manually download the images.
      Here is the link to the Pillow library: bit.ly/47VOQCc

  • @MyDigitalHub
    @MyDigitalHub Год назад +1

    Can you add paintbrush feature next? Thanks

    • @CodeCraftersCorner
      @CodeCraftersCorner  Год назад +2

      Thank you, @MyDigitalHub, for the suggestion! While I don't have a paintbrush feature directly in this workflow, Gradio has an ImageEditor component which allows editing uploaded images when used as an input field. You can find more information in the official guide here: bit.ly/4ayH8kh. Hope this helps.

  • @KzbarKawai
    @KzbarKawai 8 месяцев назад

    Great thx. You are my lifesaver!😁

  • @EternalAI-v9b
    @EternalAI-v9b 3 месяца назад

    is there a way to implement FORGE UI instead? I heard it uses even LESS vram

    • @CodeCraftersCorner
      @CodeCraftersCorner  3 месяца назад +1

      Stable Diffusion Forge uses Gradio too. So you can use the Gradio API with it. The code will be the same. Instead of connecting to ComfyUI, you will connect the the Gradio API

    • @EternalAI-v9b
      @EternalAI-v9b 3 месяца назад

      @@CodeCraftersCorner Great. another question : if I had connect from the exterior (allow external APIs) and haev gradio on MY PC. Is there a way to put in a place an authentification, i mean not just a certain IP or certain device, but actually only allow someone who "id"ed himself (like user/password), otherwise the message would not be sent to the pc or at least it would be blocked and no generation happening.
      ?

  • @archi_designer
    @archi_designer 7 месяцев назад

    Very helpful, thanks
    Did you try to get the result image via websocket?

    • @CodeCraftersCorner
      @CodeCraftersCorner  7 месяцев назад +1

      Yes, websocket works as well and can retrieve the intermediate images like preview image nodes.

    • @archi_designer
      @archi_designer 7 месяцев назад

      @@CodeCraftersCorner
      Nice , can you make a tutorial about that?
      i see many people asked about it

    • @CodeCraftersCorner
      @CodeCraftersCorner  7 месяцев назад

      Hello, I made the tutorial. Here is the link: ruclips.net/video/kmZqoLJ2Dhk/видео.html

    • @archi_designer
      @archi_designer 7 месяцев назад

      @@CodeCraftersCorner
      Thank you very much

    • @CodeCraftersCorner
      @CodeCraftersCorner  7 месяцев назад

      👍

  • @fernandodiaz8231
    @fernandodiaz8231 Год назад +1

    The project you explain in your video is very interesting. The only limitation I see is that you can only run the solution in LOCAL mode. Is there an option to deploy to a hosting service that supports Python, Gradio and GPU?

    • @CodeCraftersCorner
      @CodeCraftersCorner  Год назад

      Thank you, @fernandodiaz8231! Yes, you can host ComfyUI on a server and set it up to get a public URL instead of the localhost one. Similarly, you can use Gradio public URL and the code will still works.

  • @AnasJafri-s6k
    @AnasJafri-s6k 2 месяца назад

    Hey, when I am applying same thing on my workflow I am just getting "Running on anaother tab" on progress bar and nothing is happening. Please please Help!!!!!!

    • @CodeCraftersCorner
      @CodeCraftersCorner  2 месяца назад

      Can you check if ComfyUI is generating the image from the terminal? It is possible that your application is stuck in an endless loop. Try to look into the while loop, you can add print statements or any other way to debug it. The running in another tab is normal when you have more than 1 tab with ComfyUI open.

  • @the_one_and_carpool
    @the_one_and_carpool Год назад +1

    do you think it possible to make a deepdream gradio

    • @CodeCraftersCorner
      @CodeCraftersCorner  Год назад

      I cannot say for certain, @the_one_and_carpool! While I'm not familiar with deepdream, if it follows the input > process > output structure, creating a Gradio application should be possible. If the underlying workflow has multiple steps, consider adding buttons for each step or utilize Gradio tabs to keep things organized. Additionally, we have to consider whether making a standalone application or connecting the Gradio application with an API.

  • @urieldeveaud
    @urieldeveaud 7 месяцев назад

    Very nice! i am wondering if this is also possible directly from ComfyUI JS ?

    • @CodeCraftersCorner
      @CodeCraftersCorner  7 месяцев назад +1

      Yes, you can use JS directly since it does support websockets.

    • @urieldeveaud
      @urieldeveaud 7 месяцев назад

      @@CodeCraftersCorner yes, i mean that it is possible to build a very customized node with new widgets as user interface using JS. anyway, your videos are very good!

    • @CodeCraftersCorner
      @CodeCraftersCorner  7 месяцев назад

      Hello, you may want to look into custom nodes then. To answer the question, yes, you can build new widgets.

  • @mehradbayat9665
    @mehradbayat9665 11 месяцев назад

    Hello Sharvin, is there anyway to check the network setting on gradio to see what information was sent via payload to the API (that generated the image)? I am trying to increment the seed in python so I can generate new images on every click generate action.

    • @CodeCraftersCorner
      @CodeCraftersCorner  11 месяцев назад

      Hello Mehrad, yes, you can use your browser's developer's tool to check the network activities. This will give you the payload which Gradio is sending to the backend. This does not show you what is sent to ComfyUI. I have added a new file to the Github repo (link in video description). The file is called "example_with_random_seed.py" where you can take a look at how to manipulate the seed. You will need line 4 and 38. Make sure to change "3" to your node ID number.

    • @mehradbayat9665
      @mehradbayat9665 11 месяцев назад

      Thank you, I took a look - I just used 'prompt["3"]["inputs"]["seed"] += 1'. Do you do any tutoring, I can pay you for pair programming.@@CodeCraftersCorner

    • @mehradbayat9665
      @mehradbayat9665 11 месяцев назад

      ...but it doesn't work if I enter the same prompt, only 1 image is generated

    • @mehradbayat9665
      @mehradbayat9665 11 месяцев назад

      nevermind, I used 'with open("workflow_api.json", "w") as file_json:' after I increment the seed by 1, and it works now for some reason...

    • @CodeCraftersCorner
      @CodeCraftersCorner  10 месяцев назад

      @mehradbayat9665 Glad you got it to work!

  • @seadude
    @seadude 10 месяцев назад

    Excellent!

  • @beatemero6718
    @beatemero6718 10 месяцев назад

    Hello Sir! Your tutorials are amazing! I used comfyUI quite a lot and am very comfortable using it. This tutorial is next on my list but I also have a question. Is it possible to basically do the same thing but with a Mobile Application? I'm planning to create a simple yet fun Image worflow and would like to release it as a Mobile app. Would that be possible and if so, could you tell me what I would have to learn to get to that point?

    • @CodeCraftersCorner
      @CodeCraftersCorner  10 месяцев назад +1

      Thank you, @beatemero6718. Yes, you can. At the end of the video, I show how to use the app on mobile. If you are making a native application, you will need to make you own ComfyUI API depending on the workflow used.

    • @beatemero6718
      @beatemero6718 10 месяцев назад +1

      @@CodeCraftersCorner oh wow! Thank you for responding. I will watch the video to the end as soon as i have Time. Looking forward to it. 😁

    • @CodeCraftersCorner
      @CodeCraftersCorner  10 месяцев назад +1

      👍

  • @AbhijeetMaurya-g1l
    @AbhijeetMaurya-g1l 4 месяца назад

    thanks, it very helpful but its gradio only work for 72h so how we make them available for 24*7 on the web, basically I want to make the web application so it should be accessed by anyone and any time on the web

    • @CodeCraftersCorner
      @CodeCraftersCorner  4 месяца назад

      Thanks for watching. Yes, when using gradio's public URL, there is a time limit restriction. You can look into setting up your own Share Server on your own cloud server to overcome this restriction. here is a great resource for sharing gradio app: bit.ly/3TQqjK7

    • @AbhijeetMaurya-g1l
      @AbhijeetMaurya-g1l 4 месяца назад

      @@CodeCraftersCorner hello sir I have tried some thing but I got way to much confused I request to provide the guides to on this please sir

  • @fintech1378
    @fintech1378 11 месяцев назад +1

    how to replicate what we have on comfyUI in python? instead of calling API

    • @CodeCraftersCorner
      @CodeCraftersCorner  11 месяцев назад

      Hi @fintech1378! If you do not want to use the API, then you will have to implement the image generation with stable diffusion pipeline from HuggingFace. Of course, you will require handling tokenizing the text, loading and converting images to tensors and passing them over to the pipeline. Note that, you will not get the benefit of optimal loading of models that ComfyUI provide out to the box. That will have to be implemented manually. It is possible but too time consuming. If you are planning on doing everything from scratch, check out the documentation on HuggingFace website.

  • @alpaykasal2902
    @alpaykasal2902 9 месяцев назад

    Thank you for this tutorial, it's super clear! Your approach is very interesting, you are sending the entire workflow json each time in a new payload. I never thought of doing it that way. I will be using radio buttons to basically assemble many parts of a complete prompt - so I will be changing the positive prompt in the json each time. I have a question however - I do plan to run this on cloud GPU's, I suppose I will need to select a service provider which let's me manage the storage/file system if I am to wrangle the output images. ps: I sent you an email offering some freelance work if you're open to it. Thanks again.

    • @CodeCraftersCorner
      @CodeCraftersCorner  9 месяцев назад

      Hello @alpaykasal2902! Thank you, I replied to your email.
      Yes, you will need the storage/file system.

  • @mrleotheo
    @mrleotheo 8 месяцев назад

    If I use "share=True" it doesn't work in both local and public URL's

    • @CodeCraftersCorner
      @CodeCraftersCorner  8 месяцев назад +1

      Hello @mrleotheo! when you use share=True, you will get two URLs in the terminal. One is localhost and the other is a public URL provided by Gradio. If you want to use your public ip address, you will need to do additional setup. You can check the Gradio official documentation for that.

    • @mrleotheo
      @mrleotheo 8 месяцев назад

      @@CodeCraftersCorner thank you for fast answer. I will check it more more carefully

    • @CodeCraftersCorner
      @CodeCraftersCorner  8 месяцев назад

      @mrleotheo Here is the link with some solutions: bit.ly/3TQqjK7

    • @mrleotheo
      @mrleotheo 8 месяцев назад

      @@CodeCraftersCorner thank you, I just try to sharing demo like in your video, but it doesn't work. Only white screen. If I add prevent_thread_lock=True - it shows "Killing tunnel"

    • @CodeCraftersCorner
      @CodeCraftersCorner  8 месяцев назад

      @mrleotheo It might be some network firewall on your computer. Not sure exactly. Sorry!

  • @Herbstleid
    @Herbstleid 9 месяцев назад

    thx a lot

  • @seancondev3321
    @seancondev3321 7 месяцев назад

    hmmm. Infinite while loops - nice

    • @CodeCraftersCorner
      @CodeCraftersCorner  7 месяцев назад

      Thanks. You can also use Websockets which allows getting the intermediate preview images but you will have to use the same while loop.

  • @mehradbayat9665
    @mehradbayat9665 10 месяцев назад

    Hello Sharvin, I don't know if my comment keeps getting deleted or I can't see it, anyway, I was wondering if you offer pair programming/tutor services. I am looking for 4 hours/twice a week, it would amount to $120/week, but I can negotiate if you are interested. You are an excellent teacher, would love to discuss further.

    • @CodeCraftersCorner
      @CodeCraftersCorner  10 месяцев назад

      Hello Mehrad, Thank you so much for your kind words. I'm open to discussing the details further. Could you please send me an email at CodeCraftersCorner@gmail.com, so we can discuss the details; schedule, pricing, and any other specific requirements you may have.