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
49.87k stars 5.25k forks source link

[Feature Request] API support in Workflow JSON #2275

Open ecornbower opened 9 months ago

ecornbower commented 9 months ago

For external integrations, it is currently impossible to generate an API call solely from a workflow json file. This is because the input names for widgets are not stored in the file, only the values are:

"inputs": [
        {
          "name": "clip",
          "type": "CLIP",
          "link": 3
        }
      ],
"widgets_values": [
        "beautiful scenery nature glass bottle landscape, , purple galaxy bottle,"
      ]

You need to call the object_info endpoint and parse the available nodes to determine what the values should be. The above code eventually becomes the following when sending to the API:

"6": {
    "inputs": {
      "text": "beautiful scenery nature glass bottle landscape, , purple galaxy bottle,",
      "clip": [
        "4",
        1
      ]
    },
    "class_type": "CLIPTextEncode"
  },

I propose that the input widget names are added to the exported JSON files to help build API calls. There would be several ways to do this, but the easiest for backwards compatibility would be to add a widgets_names array.

"widgets_names": ["text"],
"widgets_values": [
        "beautiful scenery nature glass bottle landscape, , purple galaxy bottle,"
      ]

Even better if it were changed to an object:

"widgets": {
  "text": "beautiful scenery nature glass bottle landscape, , purple galaxy bottle,"
}

That way the widget inputs don't have to rely on the index value anymore.

@comfyanonymous Let me know if this is something you're interested in supporting. Happy to submit a PR if you approve.

philmaas commented 9 months ago

+1 Collecting past Issues here for reference as this feature has been requested several times, should consolidate:

https://github.com/comfyanonymous/ComfyUI/issues/2031 https://github.com/comfyanonymous/ComfyUI/issues/1433 https://github.com/comfyanonymous/ComfyUI/issues/1326

are there any related PRs in progress from someone?

ecornbower commented 9 months ago

@philmaas Thanks for collecting those issues. I believe they are mainly referring to the exported API JSON, whereas I'd like to add this data directly to the exported workflow json and image metadata. That way the workflow will always contain all of the information you'd need to call the API.

I think it makes sense to keep the API endpoints as simple as possible, and encourage users to work with the workflow files and then transform the data to the required API format.

I'm working on a Typescript / JS library to make it easier to parse the workflow files for external applications, if anyone is interested. But right now it requires you to pass in the object_info json in order to generate an API file.