Skip to content

About

comfyui ws api wrapper.

Resources

Stars

33 stars

Watchers

1 watching

Forks

Repository files navigation

simple_comfyui_wrapper

中文readme Simple ComfyUI backend WebSocket API wrapper
Simple frontend + RESTful API backend

Features:

  • REST API
  • User management
  • Simple FIFO scheduler
  • Keep images from ComfyUI output
  • Comfyui separate network
  • Easy and simple logic
  • 2 examples for text input and image input

REST API

Lightweight Flask framework.


User Management

User credentials are stored in a JSON file:

{
  "users": {
    "user1": "password1",
    "user2": "password2"
  }
}

FIFO Scheduler

  • Each user is allowed only one running instance.
  • If another user is executing, the request will be queued and return the queue number.
  • There is no queue monitoring code; you need to implement your own monitoring logic in the frontend.
  • Results are cached. Subsequent submissions will be ignored, and the result will be fetched from the cache.

All Uploads and ComfyUI Images Are Kept

  • data: This directory stores the ComfyUI API workflows.
  • uploads: This directory stores user-uploaded images.
  • comfyui_img: This directory stores images generated by ComfyUI.

Frontend Examples

Two examples are provided for text input and image input.


Installation

  1. Create a virtual environment:

    python -m venv venv
    source venv/bin/activate
  2. Install dependencies:

    pip install -r requirements.txt
  3. Update configuration:

    • Set COMFYUI_SERVER_ADDRESS = "127.0.0.1:8188"
    • Set FLASK_ADDR = 'http://127.0.0.1:5000'

Example Screenshots

Example Image 1

Example Image 2

Example Image 3

Example Image 4

If you have input image use : load_img_from_url

please img preview as image output image_preview_node


Adding a New Workflow

  1. Copy the workflow API file into the data directory.

  2. Create a new route in the Flask app:

    @app.route('/api/new_api', methods=['POST'])
  3. Load/overwrite values and fill the task:

    (prompt, ret,) = get_promp_from_json('api_test.json')
    data = request.get_json()
    text = data.get('text')
    task['prompt'] = prompt
    task['text'] = text
    task['call'] = api1
  4. Define the API function:

    def api1(task):  # t2i, input: text
        prompt = task['prompt']
        prompt['42']['inputs']['text'] = task['text']
        output_images = process_comfyui(prompt)
        (p,) = save_img_result("comfyui_img", "t2i", output_images[0])   #output_image array is all output image_preview 
        return f"{FLASK_ADDR}/{p}"
  5. Follow this template to add new workflows.


Happy hacking! 🚀

About

comfyui ws api wrapper.

Resources

Stars

33 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages