comfyui-utils


Namecomfyui-utils JSON
Version 0.0.1 PyPI version JSON
download
home_page
SummaryUtilities for working with the ComfyUI API.
upload_time2023-11-09 08:46:07
maintainer
docs_urlNone
author
requires_python>=3.9
license
keywords comfyui api
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ComfyUI utils

This package provides simple utils for:
1. Parsing out prompt arguments, e.g. "a beautiful forest $num_steps=12"
2. Running a workflow in parsed API format against a ComfyUI endpoint, with callbacks for specified events.

It's designed primarily for developing casual chatbots (e.g. a Discord bot) where users can adjust certain parameters and receive live progress updates.

Limitations:
- Only integer arguments are currently supported in addition to the prompt itself. The plan is to add at least floats and strings.
- Only one output from the workflow is supported.

Supports:
- Arbitrary number of integer args embedded in the main string prompt.
- Queuing with a callback when the queue position changes.
- Fetching cached results.
- Reporting intermediate progress of nodes like `KSampler`.


## Install

```
pip install comfyui_utils
```

## Usage

(better docs are coming, for now please look at the source code / sample script)

```
from comfyui_utils import gen_prompts, comfy
gen_prompts.make_config("GenVid", [gen_prompts.IntArg("num_steps", default_value=12, min_value=1, max_value=80)])
...
try:
    parsed = gen_prompts.parse_args(raw_prompt, prompt_config)
except ValueError as e:
    print(f"Invalid prompt {e.args[0]}")
prompt_data = ...
class Callbacks(comfy.Callbacks):
    ...
await comfyui.submit(prompt_data, Callbacks())
def on_load(data_buffer):
    ...
await comfyui.fetch(backend_filepath, on_load)
```

## Example

To test the library with a sample SDXL workflow, run the following after installing (replace the address with your ComfyUI endpoint). Make sure your ComfyUI has `sd_xl_base_1.0.safetensors` and `sd_xl_refiner_1.0.safetensors` installed (or replace the workflow).

```python
comfy_ui_example_e2e\
  --address='192.168.0.10:11010'\
  --prompt='a smiling potato $base_steps=8$refiner_steps=3'\
  --output='./potato.png'
```
The single quotes are important so your shell doesn't try to parse the `$`'s. Expected output:
```
Queuing workflow.
Queue position: #0
Base...
Base: 1/8
Base: 2/8
Base: 3/8
Base: 4/8
Base: 5/8
Base: 6/8
Base: 7/8
Base: 8/8
Refiner...
Refiner: 1/3
Refiner: 2/3
Refiner: 3/3
Decoding...
Saving image on backend...
Result (cached: no):
{'images': [{'filename': 'ComfyUI_00101_.png', 'subfolder': '', 'type': 'output'}]}
```
The file will be saved in the root directory.

## Use your own workflow

After finalizing the workflow, use the "Save (API format)" button to store the workflow. Then, edit the `PromptConfig` in the script to reflect the arguments you wish to make available, and ensure the prompt has them replaced after parsing.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "comfyui-utils",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "",
    "keywords": "comfyui,api",
    "author": "",
    "author_email": "Andrey Ryabtsev <ryabtsev.code@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/90/06/fdad3304db74dd5f0c6c7010b0797989baa30406e8c6d57c8c6bdfe18b6b/comfyui_utils-0.0.1.tar.gz",
    "platform": null,
    "description": "# ComfyUI utils\n\nThis package provides simple utils for:\n1. Parsing out prompt arguments, e.g. \"a beautiful forest $num_steps=12\"\n2. Running a workflow in parsed API format against a ComfyUI endpoint, with callbacks for specified events.\n\nIt's designed primarily for developing casual chatbots (e.g. a Discord bot) where users can adjust certain parameters and receive live progress updates.\n\nLimitations:\n- Only integer arguments are currently supported in addition to the prompt itself. The plan is to add at least floats and strings.\n- Only one output from the workflow is supported.\n\nSupports:\n- Arbitrary number of integer args embedded in the main string prompt.\n- Queuing with a callback when the queue position changes.\n- Fetching cached results.\n- Reporting intermediate progress of nodes like `KSampler`.\n\n\n## Install\n\n```\npip install comfyui_utils\n```\n\n## Usage\n\n(better docs are coming, for now please look at the source code / sample script)\n\n```\nfrom comfyui_utils import gen_prompts, comfy\ngen_prompts.make_config(\"GenVid\", [gen_prompts.IntArg(\"num_steps\", default_value=12, min_value=1, max_value=80)])\n...\ntry:\n    parsed = gen_prompts.parse_args(raw_prompt, prompt_config)\nexcept ValueError as e:\n    print(f\"Invalid prompt {e.args[0]}\")\nprompt_data = ...\nclass Callbacks(comfy.Callbacks):\n    ...\nawait comfyui.submit(prompt_data, Callbacks())\ndef on_load(data_buffer):\n    ...\nawait comfyui.fetch(backend_filepath, on_load)\n```\n\n## Example\n\nTo test the library with a sample SDXL workflow, run the following after installing (replace the address with your ComfyUI endpoint). Make sure your ComfyUI has `sd_xl_base_1.0.safetensors` and `sd_xl_refiner_1.0.safetensors` installed (or replace the workflow).\n\n```python\ncomfy_ui_example_e2e\\\n  --address='192.168.0.10:11010'\\\n  --prompt='a smiling potato $base_steps=8$refiner_steps=3'\\\n  --output='./potato.png'\n```\nThe single quotes are important so your shell doesn't try to parse the `$`'s. Expected output:\n```\nQueuing workflow.\nQueue position: #0\nBase...\nBase: 1/8\nBase: 2/8\nBase: 3/8\nBase: 4/8\nBase: 5/8\nBase: 6/8\nBase: 7/8\nBase: 8/8\nRefiner...\nRefiner: 1/3\nRefiner: 2/3\nRefiner: 3/3\nDecoding...\nSaving image on backend...\nResult (cached: no):\n{'images': [{'filename': 'ComfyUI_00101_.png', 'subfolder': '', 'type': 'output'}]}\n```\nThe file will be saved in the root directory.\n\n## Use your own workflow\n\nAfter finalizing the workflow, use the \"Save (API format)\" button to store the workflow. Then, edit the `PromptConfig` in the script to reflect the arguments you wish to make available, and ensure the prompt has them replaced after parsing.\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Utilities for working with the ComfyUI API.",
    "version": "0.0.1",
    "project_urls": {
        "Homepage": "https://github.com/andreyryabtsev/comfyui_utils"
    },
    "split_keywords": [
        "comfyui",
        "api"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "49c4da49b0aa66862e8d8a2adb370d06896f129987c8f0f5d14d1f3b98878e05",
                "md5": "f6e8f2d505090425bb0f504db3acd077",
                "sha256": "238248862ae2dbf29d7887fe14fc7e1f5b64d41029107b070f6e1658ec7db875"
            },
            "downloads": -1,
            "filename": "comfyui_utils-0.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f6e8f2d505090425bb0f504db3acd077",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 8941,
            "upload_time": "2023-11-09T08:46:06",
            "upload_time_iso_8601": "2023-11-09T08:46:06.345396Z",
            "url": "https://files.pythonhosted.org/packages/49/c4/da49b0aa66862e8d8a2adb370d06896f129987c8f0f5d14d1f3b98878e05/comfyui_utils-0.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9006fdad3304db74dd5f0c6c7010b0797989baa30406e8c6d57c8c6bdfe18b6b",
                "md5": "9b3122fb606ee6f6c76d01b2b5f7a9aa",
                "sha256": "f1080e033fdc510ac4c4a320d5e3cce1f80a743c0d4e57bde420f50cde6d37de"
            },
            "downloads": -1,
            "filename": "comfyui_utils-0.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "9b3122fb606ee6f6c76d01b2b5f7a9aa",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 7647,
            "upload_time": "2023-11-09T08:46:07",
            "upload_time_iso_8601": "2023-11-09T08:46:07.532009Z",
            "url": "https://files.pythonhosted.org/packages/90/06/fdad3304db74dd5f0c6c7010b0797989baa30406e8c6d57c8c6bdfe18b6b/comfyui_utils-0.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-09 08:46:07",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "andreyryabtsev",
    "github_project": "comfyui_utils",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "comfyui-utils"
}
        
Elapsed time: 0.13314s