ComfyUI icon indicating copy to clipboard operation
ComfyUI copied to clipboard

Automatically start workflow with "Auto Queue" during ComfyUI startup

Open Shyryp opened this issue 1 year ago • 10 comments

Feature Idea

I would like to be able to specify a parameter in the bat file when running main.py ComfyUI that will force an endless queue for a specific specified workflow. For example, I suggest the following command: ComfyUI\main.py --infinite-queue-at-startup "C:/Workflows/workflow1.json"

--infinite-queue-at-startup is a parameter that will force ComfyUI to start the workflow immediately after ComfyUI is launched. Together with --infinite-queue-at-startup, it is necessary (but can be optional) to pass the path to the workflow that needs to be launched in an infinite loop after ComfyUI is launched - for example "C:/Workflows/workflow1.json".

It would also be useful to add the parameter --ignore-infinite-queues-on-startup, which will ignore the automatic start of the endless queue for previously opened browser tabs with auto-queue enabled. But this parameter should not affect the running workflow, caused by the parameter --infinite-queue-at-startup

This would be incredibly useful for those cases when ComfyUI is launched on servers or on machines that are restarted very often.

If such functionality already exists, I will be glad to receive your tips!

Existing Solutions

I didn't find it, I didn't see such a parameter or functionality in the list of supported parameters of main.py

Other

No response

Shyryp avatar Jul 27 '24 18:07 Shyryp

So you want to start ComfyUI and have it run the workflow automatically and endlessly? What is the use case here? Why would you want to endlessly run the same workflow without changes?

To accomplish this today you could simply call the API with the api workflow JSON endlessly through your own script.

robinjhuang avatar Jul 30 '24 00:07 robinjhuang

@robinjhuang "Why would you want to endlessly run the same workflow without changes?" Answer: There are workflows that rely on external input data (for example, text files or images in the machine's storage, and sometimes external databases). In this case, text files and/or images are changed/replaced during the infinite cycle of the workflow (some files are updated by the workflow itself (and then used by it in the next cycle), for example - the counter of generated images).

Therefore, in fact, the workflow does not change manually at all - all the necessary data automatically comes from external files and affects the workflow. The maximum that can be changed manually is prompts in text files or some other technical things. Such a separation is necessary so that workflows do not depend on data, and data does not depend on workflows, since each machine can have its own set of files/settings, and, in case of updating/replacing the workflow, the user does not have to change anything in the workflow itself.

And I need automatic launch on an infinite cycle for the cases that I described above (frequent restart of the work machine; the need for greater automation, etc.). Overall, there are a lot of situations where this can be used.

Thanks for the tip about the API!

If you have any example of such API usage (with infinite loop), it would be great to see it here. What I'm wondering now is how can I set an infinite loop (Auto Queue) in functions like this queue_prompt? What parameter/command is responsible for this, do you have a simple answer?

Anyway, thanks for the tip, I'll try to study the API and figure it out! If I figure it out, I will share it here with the community.

Shyryp avatar Jul 30 '24 01:07 Shyryp

@robinjhuang "Why would you want to endlessly run the same workflow without changes?" Answer: There are workflows that rely on external input data (for example, text files or images in the machine's storage, and sometimes external databases). In this case, text files and/or images are changed/replaced during the infinite cycle of the workflow (some files are updated by the workflow itself (and then used by it in the next cycle), for example - the counter of generated images).

Therefore, in fact, the workflow does not change manually at all - all the necessary data automatically comes from external files and affects the workflow. The maximum that can be changed manually is prompts in text files or some other technical things. Such a separation is necessary so that workflows do not depend on data, and data does not depend on workflows, since each machine can have its own set of files/settings, and, in case of updating/replacing the workflow, the user does not have to change anything in the workflow itself.

And I need automatic launch on an infinite cycle for the cases that I described above (frequent restart of the work machine; the need for greater automation, etc.). Overall, there are a lot of situations where this can be used.

Thanks for the tip about the API!

If you have any example of such API usage (with infinite loop), it would be great to see it here. What I'm wondering now is how can I set an infinite loop (Auto Queue) in functions like this queue_prompt? What parameter/command is responsible for this, do you have a simple answer?

Anyway, thanks for the tip, I'll try to study the API and figure it out! If I figure it out, I will share it here with the community.

If your workflow depends on external files, the correct approach would be to create and use a custom node that can detect changes in the external files. For this purpose, ComfyUI provide an interface in custom nodes that returns a hash value called IS_CHANGED.

If it's difficult to detect changes, you can use a trick like return float("NaN") inIS_CHANGED to make it always considered as changed.

ltdrdata avatar Jul 30 '24 08:07 ltdrdata

Sorry to slightly hijack but I'm looking for a way to queue even just once at startup (although auto queue would be better). I generate images all throughout the day and my GPU is relatively poor, so output is slow. But more importantly, it takes a long time to initialize my workflow the first time I queue, and that initialization slows down the rest of my running processes. I'd just like it to initialize a regular "mono" queue at startup so I'm not incentivized to wait until I'm not busy in Ableton Live or something. Plus it's just nice to know image generation is always ready.

robertalanbevan avatar Aug 02 '24 03:08 robertalanbevan

Sorry to slightly hijack but I'm looking for a way to queue even just once at startup (although auto queue would be better). I generate images all throughout the day and my GPU is relatively poor, so output is slow. But more importantly, it takes a long time to initialize my workflow the first time I queue, and that initialization slows down the rest of my running processes. I'd just like it to initialize a regular "mono" queue at startup so I'm not incentivized to wait until I'm not busy in Ableton Live or something. Plus it's just nice to know image generation is always ready.

Handling this is somewhat tricky because the current workflow execution is dependent on the frontend. If we limit the ready state to the default workflow and only up to the point where checkpoint loading is prepared, it might be possible with a little trick. (For this to work, a feature must be provided to set the default checkpoint in the default workflow.) However, if you load a different workflow, the ready state will be invalidated immediately.

ltdrdata avatar Aug 02 '24 16:08 ltdrdata

Hey folks, still looking around if there's any current methods of doing this, but figured I'd put my two cents in while I'm here.

My use case is starting an instance of ComfyUI at boot, with a particular workflow, and setting it to autoqueue hand in hand with nodes from Serving Toolkit to host a discord bot with whatever workflow I'm messing with that I think other people in a few communities would enjoy.

Right now working on figuring out scripting a timer that unloads the models, which I have most of what I need for, and is unrelated to this, but there's you're usecase haha.

saphtea avatar Oct 10 '24 22:10 saphtea

I'm exactly at this point but using websockets serving instead of Discord...So we are a couple here :)

Andergraw avatar Nov 12 '24 09:11 Andergraw

Hey guys,

I just made a custom node Instant Queue Key Control to workaround this issue. Here’s a screenshot of it in action:

CleanShot 2024-11-13 at 01 29 33

This node lets you toggle the Instant Queue button with a shortcut key, automatically start the Instant Queue with a customizable countdown timer, and could run workflows automatically upon loading.

To enable this feature in your own workflow, simply search for ComfyUI Web Viewer in the ComfyUI Manager, then add the Instant Queue Key Control @ vrch.ai node.

The ComfyUI Web Viewer project can be checked here: https://github.com/VrchStudio/comfyui-web-viewer

I also post a discussion at Reddit r/comfyui channel with details, see https://www.reddit.com/r/comfyui/comments/1gq288t/not_sure_if_anyone_else_needs_it_but_i_made_an/

Tz-H avatar Nov 13 '24 02:11 Tz-H

This is great, thank you! Any chance you could add Queue (Change) as an option? Thank you so much!

Andergraw avatar Nov 15 '24 11:11 Andergraw

This is great, thank you! Any chance you could add Queue (Change) as an option?

Thank you so much!

I’m curious to know which senorio requires a Queue (Change) to automatically load and run. I created this Queue (Instant) node because we need it for our real-time interactive art project. Can you help me understand this better?

Tz-H avatar Nov 15 '24 11:11 Tz-H

Maybe live painting/drawing ?

elthariel avatar Nov 20 '24 16:11 elthariel

This is great, thank you! Any chance you could add Queue (Change) as an option? Thank you so much!

I’m curious to know which senorio requires a Queue (Change) to automatically load and run. I created this Queue (Instant) node because we need it for our real-time interactive art project. Can you help me understand this better?

Hey, sorry for the late answer! So my scenario is a ComfyUI server waiting with a Websocket client node and I thought I needed a Queue (Change) node but I was testing and it's probably the same with the Instant one. I just need the workflow to come back to the listening node after sending the image back to the web app.

Andergraw avatar Nov 20 '24 18:11 Andergraw

This is great, thank you! Any chance you could add Queue (Change) as an option? Thank you so much!

I’m curious to know which senorio requires a Queue (Change) to automatically load and run. I created this Queue (Instant) node because we need it for our real-time interactive art project. Can you help me understand this better?

Hey, sorry for the late answer! So my scenario is a ComfyUI server waiting with a Websocket client node and I thought I needed a Queue (Change) node but I was testing and it's probably the same with the Instant one. I just need the workflow to come back to the listening node after sending the image back to the web app.

Hey @Andergraw

I've updated the node to support Queue (Change) option now, see my screenshot below:

https://github.com/user-attachments/assets/9541fbe2-f9db-4e97-9e5a-b48c295bd4dd

How to use

Simply search and installComfyUI Web Viewer via the ComfyUI Manager, then add the Instant Queue Key Control @ vrch.ai node into your workflow.

More details about the ComfyUI Web Viewer project can be checked here: https://github.com/VrchStudio/comfyui-web-viewer

Tz-H avatar Nov 24 '24 05:11 Tz-H

Sorry I never answered you, that's amazing, thank you so much for your help!

Andergraw avatar Dec 31 '24 11:12 Andergraw