Using  Stable Diffusion  text-to-image generator  via  ComfyUI API

ComfyUI

ComfyUI is free and locally installed SD variation. It gains popularity as we speak due to its simplicity and speed for the most users and wider-than-A1111 range of models. It provides greater level of control for more advanced users. The user interface is intuitive for some and not-so-much for others depending on your similar software products you have been using before. Being able to visual design the workflow of text-to-image generation is powerful and flexible approach that requires some understanding of the mechanics of the workflow but provides you with ability to borrow pieces of workflows others have been created.

  Take a look at Beginner’s Guide to ComfyUI


ComfyUI Installation

The original location is at https://github.com/comfyanonymous/ComfyUI and you can follow the instructions from there.

Alternatively, you can follow a short (2:44 min) installation clip, another more detailed video is HERE.

ComfyUI portable installation is very easy and it has API access by default. Once you install ComfyUI (including one or more models) you can call it from Scripthea straight way. ComfyUI-manager is optional for Scripthea to work.
 

The API :

The CompfyUI API is accessible from Scripthea by default after ComfyUI installation.

Before start using ComfyUI in Scripthea you need to:
  • go to Scripthea options on Composer tab and select SD-ComfyUI in Generator combobox. SD panel will appear on the top right
  • go SD options by clicking on three gray stripes button in SD panel
  • in options, point where the installation of ComfyUI is or more precisely point the batch file that starts your ComfyUI. Typically that is run_cpu.bat for no nVidia GPU (very slow) or run_nvidia_gpu.bat - with GPU.

The json communication commands for text-to-image generation are behind the scene. The way you operate is just set the prompt and SD parameters from their tab.

The names of the parameters are common for ComfyUI and A1111/Forge (with small exception of sampler_name, see below).

The only two exception are "sampler_name" and "Model". A number of samplers are available from sampler combobox in SD parameters tab. In case you need a sampler that you know is available but not in the combobox list you can go to config folder of Scripthea and find the file workflow_defaults.json . Inside the file (plain text) you can set your sampler_name meanwhile you need to set  "sampler_name" to <default> which will instruct Scripthea to take the default value from the file. A similar situation is for Model if you set checkbox to default the value from  workflow_defaults.json  will be used.

If CompyUI is not running , the Run local server button becomes enabled so you can start your local server of SD-ComfyUI from there. If the button is disabled that means either the SD server is running or if it is nor runnig, but the path to it is not been set (or correct). 

NB ComfyUI offers variety of modules (nodes). Each configuration of nodes having its own workflow json file. Scripthea needs to send a workflow file to ComfyUI API, so for now the nodes configuration (workflow) is fixed to the initial default one (workflow_defaults.json ). As I learn more and more ComfyUI I will make the correspondence SD parameters to workflow structure more flexible (stay tuned).

Set Stable Diffusion parameters with API

All the parameters here have the same meaning as in ComfyUI. You can save/retrieve parameter setting from the group on the right (SD parameters setting). Plus button will add new p.setting to the setting list and minus button will remove the active setting from the list. For changing the active p.setting you simply pick one from the list of the combo-box.

In Auto-sync mode when you change active p.setting the old p.setting will be saved before loading the new one.

If you switch Auto-sync off you have to do this manually using left and right buttons (see the buttons hints).


Comfy workflow templates

Workflow templates provide a new level of flexibility using ComfyUI, which is very flexible by itself but not that obvious to use. Here is How to use and create workflow templates webpage.

Side note: as long as you use the default workflow you (usually) don't need to deal with templates.