Stable Diffusion web UI (with a DirectML patch)
Go to file
2022-09-09 09:15:36 +03:00
ESRGAN ESRGAN support 2022-09-04 18:54:12 +03:00
modules add an option to show negative prompt 2022-09-09 09:15:36 +03:00
scripts make X/Y plot's S/R apply to negative prompt as well. 2022-09-09 08:58:31 +03:00
.gitignore support for sd-concepts as alternatives for textual inversion #151 2022-09-08 15:36:50 +03:00
artists.csv added random artist button 2022-09-05 23:08:06 +03:00
README.md brought manual instructions up to date 2022-09-09 08:37:19 +03:00
requirements_versions.txt Add scikit-image dependency to requirements_versions.txt for windows users. 2022-09-08 05:57:22 +00:00
requirements.txt Add color correction to img2img loopback to avoid a progressive skew to magenta. Based on codedealer's PR to hlky's repo here: https://github.com/sd-webui/stable-diffusion-webui/pull/698/files. 2022-09-08 02:35:26 +00:00
screenshot.png updated interface to use Blocks 2022-08-30 21:51:30 +03:00
script.js Fixed typos in JavaScript descriptions 2022-09-08 18:19:53 +02:00
style.css add an option to show negative prompt 2022-09-09 09:15:36 +03:00
webui-user.bat brought manual instructions up to date 2022-09-09 08:37:19 +03:00
webui.bat brought manual instructions up to date 2022-09-09 08:37:19 +03:00
webui.py fix aggressive caching for extras tab 2022-09-08 23:29:36 +03:00

Stable Diffusion web UI

A browser interface based on Gradio library for Stable Diffusion.

Feature showcase

Detailed feature showcase with images, art by Greg Rutkowski

  • Original txt2img and img2img modes
  • One click install and run script (but you still must install python, git and CUDA)
  • Outpainting
  • Inpainting
  • Prompt matrix
  • Stable Diffusion upscale
  • Attention
  • Loopback
  • X/Y plot
  • Textual Inversion
  • Extras tab with:
    • GFPGAN, neural network that fixes faces
    • RealESRGAN, neural network upscaler
    • ESRGAN, neural network with a lot of third party models
  • Resizing aspect ratio options
  • Sampling method selection
  • Interrupt processing at any time
  • 4GB videocard support
  • Correct seeds for batches
  • Prompt length validation
  • Generation parameters added as text to PNG
  • Tab to view an existing picture's generation parameters
  • Settings page
  • Running custom code from UI
  • Mouseover hints fo most UI elements
  • Possible to change defaults/mix/max/step values for UI elements via text config
  • Random artist button
  • Tiling support: UI checkbox to create images that can be tiled like textures
  • Progress bar and live image generation preview

Installing and running

You need python and git installed to run this, and an NVidia videocard.

You need model.ckpt, Stable Diffusion model checkpoint, a big file containing the neural network weights. You can obtain it from the following places:

  • official download
  • file storage
  • magnet:?xt=urn:btih:3a4a612d75ed088ea542acac52f9f45987488d1c&dn=sd-v1-4.ckpt&tr=udp%3a%2f%2ftracker.openbittorrent.com%3a6969%2fannounce&tr=udp%3a%2f%2ftracker.opentrackr.org%3a1337

You optionally can use GPFGAN to improve faces, then you'll need to download the model from here.

To use ESRGAN models, put them into ESRGAN directory in the same location as webui.py. A file will be loaded as model if it has .pth extension. Grab models from the Model Database.

Automatic installation/launch

  • install Python 3.10.6 and check "Add Python to PATH" during installation. You must install this exact version.
  • install git
  • place model.ckpt into webui directory, next to webui.bat.
  • (optional) place GFPGANv1.3.pth into webui directory, next to webui.bat.
  • run webui-user.bat from Windows Explorer. Run it as normal user, not as administrator.

Troubleshooting

  • if your version of Python is not in PATH (or if another version is), edit webui-user.bat, and modify the line set PYTHON=python to say the full path to your python executable, for example: set PYTHON=B:\soft\Python310\python.exe. You can do this for python, but not for git.
  • if you get out of memory errors and your video-card has a low amount of VRAM (4GB), use custom parameter set COMMANDLINE_ARGS (see section below) to enable appropriate optimization according to low VRAM guide below (for example, set COMMANDLINE_ARGS=--medvram --opt-split-attention).
  • to prevent the creation of virtual environment and use your system python, use custom parameter replacing set VENV_DIR=- (see below).
  • webui.bat installs requirements from files requirements_versions.txt, which lists versions for modules specifically compatible with Python 3.10.6. If you choose to install for a different version of python, using custom parameter set REQS_FILE=requirements.txt may help (but I still recommend you to just use the recommended version of python).
  • if you feel you broke something and want to reinstall from scratch, delete directories: venv, repositories.
  • if you get a green or black screen instead of generated pictures, you have a card that doesn't support half precision floating point numbers (Known issue with 16xx cards). You must use --precision full --no-half in addition to command line arguments (set them using set COMMANDLINE_ARGS, see below), and the model will take much more space in VRAM (you will likely have to also use at least --medvram).
  • installer creates python virtual environment, so none of installed modules will affect your system installation of python if you had one prior to installing this.
  • About "You must install this exact version" from the instructions above: you can use any version of python you like, and it will likely work, but if you want to seek help about things not working, I will not offer help unless you this exact version for my sanity.

How to run with custom parameters

It's possible to edit set COMMANDLINE_ARGS= line in webui.bat to run the program with different command line arguments, but that may lead to inconveniences when the file is updated in the repository.

The recommndended way is to use another .bat file named anything you like, set the parameters you want in it, and run webui.bat from it. A webui-user.bat file included into the repository does exactly this.

Here is an example that runs the prgoram with --opt-split-attention argument:

@echo off

set COMMANDLINE_ARGS=--opt-split-attention

call webui.bat

Another example, this file will run the program with custom python path, a different model named a.ckpt and without virtual environment:

@echo off

set PYTHON=b:/soft/Python310/Python.exe
set VENV_DIR=-
set COMMANDLINE_ARGS=--ckpt a.ckpt

call webui.bat

What options to use for low VRAM video-cards?

You can, through command line arguments, enable the various optimizations which sacrifice some/a lot of speed in favor of using less VRAM. Those arguments are added to the COMMANDLINE_ARGS parameter, see section above.

Here's a list of optimization arguments:

  • If you have 4GB VRAM and want to make 512x512 (or maybe up to 640x640) images, use --medvram.
  • If you have 4GB VRAM and want to make 512x512 images, but you get an out of memory error with --medvram, use --medvram --opt-split-attention instead.
  • If you have 4GB VRAM and want to make 512x512 images, and you still get an out of memory error, use --lowvram --always-batch-cond-uncond --opt-split-attention instead.
  • If you have 4GB VRAM and want to make images larger than you can with --medvram, use --lowvram --opt-split-attention.
  • If you have more VRAM and want to make larger images than you can usually make (for example 1024x1024 instead of 512x512), use --medvram --opt-split-attention. You can use --lowvram also but the effect will likely be barely noticeable.
  • Otherwise, do not use any of those.

Running online

Use --share option to run online. You will get a xxx.app.gradio link. This is the intended way to use the program in collabs.

Use --listen to make the server listen to network connections. This will allow computers on local newtork to access the UI, and if you configure port forwarding, also computers on the internet.

Use --port xxxx to make the server listen on a specific port, xxxx being the wanted port. Remember that all ports below 1024 needs root/admin rights, for this reason it is advised to use a port above 1024. Defaults to port 7860 if available.

Google collab

If you don't want or can't run locally, here is google collab that allows you to run the webui:

https://colab.research.google.com/drive/1Iy-xW9t1-OQWhb0hNxueGij8phCyluOh

Textual Inversion

To make use of pretrained embeddings, create embeddings directory (in the same palce as webui.py) and put your embeddings into it. They must be .pt files, each with only one trained embedding, and the filename (without .pt) will be the term you'd use in prompt to get that embedding.

As an example, I trained one for about 5000 steps: https://files.catbox.moe/e2ui6r.pt; it does not produce very good results, but it does work. Download and rename it to Usada Pekora.pt, and put it into embeddings dir and use Usada Pekora in prompt.

How to change UI defaults?

After running once, a ui-config.json file appears in webui directory:

{
    "txt2img/Sampling Steps/value": 20,
    "txt2img/Sampling Steps/minimum": 1,
    "txt2img/Sampling Steps/maximum": 150,
    "txt2img/Sampling Steps/step": 1,
    "txt2img/Batch count/value": 1,
    "txt2img/Batch count/minimum": 1,
    "txt2img/Batch count/maximum": 32,
    "txt2img/Batch count/step": 1,
    "txt2img/Batch size/value": 1,
    "txt2img/Batch size/minimum": 1,

Edit values to your liking and the next time you launch the program they will be applied.

Manual instructions

Alternatively, if you don't want to run webui.bat, here are instructions for installing everything by hand:

:: install torch with CUDA support. See https://pytorch.org/get-started/locally/ for more instructions if this fails.
pip install torch --extra-index-url https://download.pytorch.org/whl/cu113

:: check if torch supports GPU; this must output "True". You need CUDA 11. installed for this. You might be able to use
:: a different version, but this is what I tested.
python -c "import torch; print(torch.cuda.is_available())"

:: clone web ui and go into its directory
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
cd stable-diffusion-webui

:: clone repositories for Stable Diffusion and (optionally) CodeFormer
mkdir repositories
git clone https://github.com/CompVis/stable-diffusion.git repositories/stable-diffusion
git clone https://github.com/CompVis/taming-transformers.git repositories/taming-transformers
git clone https://github.com/sczhou/CodeFormer.git repositories/CodeFormer

:: install requirements of Stable Diffusion
pip install transformers==4.19.2 diffusers invisible-watermark --prefer-binary

:: install k-diffusion
pip install git+https://github.com/crowsonkb/k-diffusion.git --prefer-binary

:: (optional) install GFPGAN (face resoration)
pip install git+https://github.com/TencentARC/GFPGAN.git --prefer-binary

:: (optional) install requirements for CodeFormer (face resoration)
pip install -r repositories/CodeFormer/requirements.txt --prefer-binary

:: install requirements of web ui
pip install -r stable-diffusion-webui/requirements.txt  --prefer-binary

:: update numpy to latest version
pip install -U numpy  --prefer-binary

:: (outside of command line) put stable diffusion model into web ui directory
:: the command below must output something like: 1 File(s) 4,265,380,512 bytes
dir model.ckpt

:: (outside of command line) put the GFPGAN model into web ui directory
:: the command below must output something like: 1 File(s) 348,632,874 bytes
dir GFPGANv1.3.pth

Note: the directory structure for manual instruction has been changed on 2022-09-09 to match automatic installation: previosuly webui was in a subdirectory of stable diffusion, now it's the reverse. If you followed manual installation before the chage, you can still use the program with you existing directory sctructure.

After that the installation is finished.

Run the command to start web ui:

python webui.py

If you have a 4GB video card, run the command with either --lowvram or --medvram argument:

python webui.py --medvram

After a while, you will get a message like this:

Running on local URL:  http://127.0.0.1:7860/

Open the URL in browser, and you are good to go.

Credits