Using  Stable Diffusion text-to-image generator via Automatic1111 or Forge web UI 

Stable Diffusion

Currently, only Stable Diffusion text-to-image generator is fully supported. In order to unlock the full potential of Scripthea one way is to have installation of Stable Diffusion webUI by AUTOMATIC1111 (aka A1111) from https://github.com/AUTOMATIC1111/stable-diffusion-webui repository. This good and brief video will lead you step by step thru the installation process. A wide (huge) variety of models are available from Hugging Face and Civitai.com (non-British users only).

An alternative to A1111 installation is SD-Forge. Forge UI is faster than A1111. It UI looks and feels like Automatic 1111, but has a lot of things already integrated although A1111 has more extentions and options to extend. Forge is supposed to runs better on older GPU's.
 


Before using Stable Diffusion text-to-image generator you need to select Stable Diffusion generator from Options in Prompt generator tab (that is if you don't see SD panel on top/right).

A1111 and Forge are undistinguishable from Scripthea point of view, they behave in the same way. If you have both installed the way to run one or the other is to browse and point webui-user.bat batch file in SD options (sdee below).

After installing Stable Diffusion A1111 you have two ways of accessing Stable Diffusion from Scripthea:

 

Note: Using API access to SD is much simpler way to generate images but the number of adjustable SD parameters is limited to what you see below. For the vast majority of cases that is enough but if you reach level you need better parameter control which webUI provides, you can always switch to py script access to Stable Diffusion image generator (see below right).

The API way (recommended):

  1. Go to stable-diffusion-webui folder and find webui-user.bat batch file.
  2. Open it in any plain-text editor, add --api  to set COMMANDLINE_ARGS=  (e.g. set COMMANDLINE_ARGS=--api) and save it.
  3. Before starting generating images in Scripthea, you need to select working image depot directory (existing or an empty one) for a storage of the incoming images.
  4. Set API mode on SD A1111/Forge tab , see SD options below.
  5. To run the SD local server you have one of two ways: first In SD panel click on the Run local server button (recommended) OR second, open terminal (command window), go to stable-diffusion-webui folder and run the same webui-user.bat .  Either way, wait from a several seconds to one minute for initialization.
  6. Set SD parameters on "Stable Diffusion" tab next to Modifiers tab.
  7. Select cue(s) and modifiers you would like to run and click Generate (for single) or Scan from Prompt Composer tab, sit back and enjoy the show.

Step 1 and 2 you need to execute only once. For regular everyday use you start from step 3.

NB You may or may not open the web interface of SD (localhost:7860), API access will work either way.
 

All the parameters here have the same meaning as in SDW. 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).

NB You can change/set the model (checkpoint) in API mode from A1111 web-UI - top/left combobox at the first tab.

The Py-script way:

  1. Copy the script prompts_from_scripthea_1_5.py from config directory of Scripthea to script directory of stable-diffusion-webui
  2. To run the SD local server you have two ways: first In SD panel click on the Run local server button OR second, open terminal (command window), go to stable-diffusion-webui folder and run the same webui-user.bat .  Either way, wait from a several seconds to one minute for initialization.
  3. If you do not see webUI of Stable Diffusion, open your web browser and go to localhost:7860 . That will shows you the web user interface (webUI) with Stable Diffusion running on the background.
  4. Open Scripthea application, and select working image depot directory for the incoming images.
  5. In Scripthea, set py script mode in SD options (the bottom of the dialog) if it is not on. You should see COMM: waiting in SD panel (top/left).
  6. Select cue(s) and modifiers you would like to try on - single or scan mode.
  7. In the first tab of SDW, on the bottom select prompts_from_scripthea_1_5 script and click on Generate in SDW (big button top/right).
  8. In Scripthea SD log and SD terminal log you should see "open session" message, so you know the tandem SDW-Scripthea tandem is ready.
    Communication label will show COMM: propmtExpect
  9. Click Generate (for single) or Scan from Prompt Composer tab, sit back and enjoy the show.

 You need to execute steps 1 only once. For regular everyday use you start from step 2.

 

 

An open communication (session) will stay open by default unless you close either app (Scripthea or SDW) or click on Reset (Scripthea side). Open session does not prevent you in doing anything within Scripthea, but SDW stays locked for the time of open session. If you click on Reset Scripthea will close the session and restart the Scripthea server, that will free the UI of SDW and allow you the do things in SDW. To start new session execute step 7 from the protocol on the left.

As you can see working with Py-script is less intuitive and would require more of your attention, so one usually use it when has a good reason for it.

 


In Options (three bar button) you will find some initial options as:

  • set the A1111 batch file (e.g.webui-user.bat), needed for Scripthea script validation at start
  • validate API to make sure that API is accessible from your A1111 installation (by default it is not)

two options are for py script mode only:

  • validation of Scripthea script is verification if the Scripthea script in SDW is the same of the one that came with the Scripthea installation. If it is not, you will be asked if you would like to copy the new one (recommended) over the old one.
  • close the active session after a scan which will allow you to modify webUI parameters

...the rest of the options are valid for both (A1111 and ConfyUI) modes

  • timeout [s] for image generation (does not count the waiting-to-cool time). If you use batch mode you may increase that time depending on the batch size.
  • close the A1111 and/or ComfyUI terminal windows if they have been opened by Scripthea