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
48.47k stars 5.1k forks source link

[Feature req] Add "flow to python code" function #232

Open mlengle opened 1 year ago

mlengle commented 1 year ago

Add ability to turn the flow into a python script that can be executed stand-alone

Exouxas commented 1 year ago

An excellent alternative to this could be to add a launch argument that takes a workflow file and possibly some prompts or filenames. Of course, it would take some time to develop either way, but generating code is generally more challenging to maintain, and knowing which nodes to keep constant and which to take arguments would require changes to all nodes.

Another option to consider is to host the workflow as a gRPC server. That could let us grab a list of nodes that can be modified and decide in our application whether we'd like to supplement with new node content or keep the workflow default values.

Overall, this general idea wouldn't cater to the "UI" aspect of this project and will probably not be worked on, but I'd love to have it as well and wouldn't mind helping if necessary.

GrimblyGorn commented 1 year ago

It seems like it might be easier to start off with trying for a "headless" mode first. Something that can run a workflow like a task with no gui required. That should be fairly minimal for modifications and would allow something similar to the originally requested feature here. Seeing as the workflow can be saved already to a .json, then loaded into the gui and run. It should be fairly easy to just run it directly instead.

While that would be more limiting than it being converted to proper code for use elsewhere. It would be useful still for task runner bots or automation scenarios. Having these workflows as automation scripts could be very useful at some point, even if they were simply being run as-is in a headless mode.

mlengle commented 1 year ago

@GrimblyGorn well, it can be composed from both declarative part (json | yaml) and code parts (runner lib) it's important to have code wrapper to be able to add such "meta" things as custom XYZ Plots etc

comfyanonymous commented 1 year ago

You should check this out: https://github.com/comfyanonymous/ComfyUI/blob/master/script_examples/basic_api_example.py