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.34k stars 5.52k forks source link

[information] ComfyUI backend questions #930

Closed sCarita closed 1 year ago

sCarita commented 1 year ago

Hello everyone,

I am a new user of ComfyUI and my main goal is to execute my workflows programmatically. To achieve this, I am currently following the example provided here: Basic API Example.

During my initial setup and experimentation on a Linux system, I noticed that the workflow.json file is not identical to what we submit via the localhost address, http://127.0.0.1:8188/prompt

My first query is regarding the correct method to retrieve the accurate prompt (in JSON format) to submit every time I want a particular workflow to be executed. Currently, I am able to obtain the prompt field by inspecting the browser's request, but I'm curious to know if there's a way to accomplish this programmatically. I browsed the source code but couldn't locate any relevant routes that would allow this through REST HTTP.

My second question pertains to the suggested approach for loading a workflow onto a ComfyUI server programmatically. Alternatively, is it required to place the .json file within a specific directory in my ComfyUI folder structure?

Any insights or suggestions will be greatly appreciated!

Thank you in advance, and I hope to contribute to the project soon.

comfyanonymous commented 1 year ago

On the latest you can "enable dev mode options" in the settings (gear beside the "Queue Size: ") this will enable a button on the UI to save workflows in api format.

You can then use these api jsons in these script examples: https://github.com/comfyanonymous/ComfyUI/tree/master/script_examples

sCarita commented 1 year ago

Thank you for the swift response, and let me congratulate you on this project!

I updated my system, re-installed all addons and it worked like you said 🙂

I have another question if you have the time: If someone sends me such json file, I am able to spin it through ComfyUI backend, but given that the backend never interacted with the original workflow, does it work?

I am asking this since I noticed we do not have any link metadata on the resulting workflow_api.json that I exported.... I might be missing something fundamental here.

comfyanonymous commented 1 year ago

They do have link metadata:

  "3": {
    "inputs": {
      "seed": 781038156354497,
      "steps": 15,
      "cfg": 9,
      "sampler_name": "dpmpp_sde_gpu",
      "scheduler": "normal",
      "denoise": 1,
      "model": [
        "4",
        0
      ],
      "positive": [
        "6",
        0
      ],
      "negative": [
        "7",
        0
      ],
      "latent_image": [
        "5",
        0
      ]
    },
    "class_type": "KSampler"
  },

This for example means the input is node with id "4" and output index 0

      "model": [
        "4",
        0
      ],

The info in the api format is only info that the backend actually needs.

The frontend has its own save format that saves node sizes, positions, etc.. When you click "queue prompt" it serializes the graph into the api format which is all the backend cares about.

sCarita commented 1 year ago

Thank you for the clarification. All makes sense. closed issue.