2022-08-22 14:15:46 +00:00
# Stable Diffusion web UI
A browser interface based on Gradio library for Stable Diffusion.
![](screenshot.png)
2022-09-04 10:08:06 +00:00
## Feature showcase
[<font size="12">Detailed feature showcase with images, art by Greg Rutkowski</font> ](https://github.com/AUTOMATIC1111/stable-diffusion-webui-feature-showcase )
- 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
2022-09-04 15:54:12 +00:00
- 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
2022-09-04 10:08:06 +00:00
- 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
2022-09-04 10:52:01 +00:00
- Possible to change defaults/mix/max/step values for UI elements via text config
2022-09-04 10:08:06 +00:00
2022-08-23 08:58:50 +00:00
## Installing and running
2022-08-22 14:15:46 +00:00
2022-09-01 10:32:34 +00:00
You need [python ](https://www.python.org/downloads/windows/ ) and [git ](https://git-scm.com/download/win )
installed to run this, and an NVidia videocard.
I tested the installation to work Windows with Python 3.8.10, and with Python 3.10.6. You may be able
to have success with different versions.
2022-08-22 14:15:46 +00:00
2022-09-02 06:49:35 +00:00
You need `model.ckpt` , Stable Diffusion model checkpoint, a big file containing the neural network weights. You
2022-08-31 08:04:19 +00:00
can obtain it from the following places:
- [official download ](https://huggingface.co/CompVis/stable-diffusion-v-1-4-original )
- [file storage ](https://drive.yerf.org/wl/?id=EBfTrmcCCUAGaQBXVIj5lJmEhjoP1tgl )
2022-08-31 08:13:24 +00:00
- 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
2022-08-22 14:15:46 +00:00
2022-08-31 08:04:19 +00:00
You optionally can use GPFGAN to improve faces, then you'll need to download the model from [here ](https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth ).
2022-08-22 14:15:46 +00:00
2022-09-04 15:54:12 +00:00
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 ](https://upscale.wiki/wiki/Model_Database ).
2022-09-02 06:49:35 +00:00
### Automatic installation/launch
2022-09-02 07:21:45 +00:00
- install [Python 3.10.6 ](https://www.python.org/downloads/windows/ )
- install [git ](https://git-scm.com/download/win )
- install [CUDA 11.3 ](https://developer.nvidia.com/cuda-11.3.0-download-archive?target_os=Windows&target_arch=x86_64 )
2022-09-02 06:49:35 +00:00
- place `model.ckpt` into webui directory, next to `webui.bat` .
2022-09-02 07:04:51 +00:00
- _*(optional)*_ place `GFPGANv1.3.pth` into webui directory, next to `webui.bat` .
2022-09-02 16:26:18 +00:00
- run `webui.bat` from Windows Explorer.
2022-09-02 06:49:35 +00:00
2022-09-02 07:21:45 +00:00
#### Troublehooting:
2022-09-04 10:08:06 +00:00
- According to reports, intallation currently does not work in a directory with spaces in filenames.
- if your version of Python is not in PATH (or if another version is), edit `webui.bat` , change the line `set PYTHON=python` to say the full path to your python executable: `set PYTHON=B:\soft\Python310\python.exe` . You can do this for python, but not for git.
2022-09-02 10:54:52 +00:00
- if you get out of memory errors and your videocard has low amount of VRAM (4GB), edit `webui.bat` , change line 5 to from `set COMMANDLINE_ARGS=` to `set COMMANDLINE_ARGS=--medvram` (see below for other possible options)
2022-09-02 16:26:18 +00:00
- 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.
- to prevent the creation of virtual environment and use your system python, edit `webui.bat` replacing `set VENV_DIR=venv` with `set VENV_DIR=` .
- 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, editing `webui.bat` to have `set REQS_FILE=requirements.txt` instead of `set REQS_FILE=requirements_versions.txt` may help (but I still reccomend you to just use the recommended version of python).
2022-09-04 10:08:06 +00:00
- if you feel you broke something and want to reinstall from scratch, delete directories: `venv` , `repositories` .
2022-09-02 07:21:45 +00:00
2022-09-02 06:49:35 +00:00
### Manual instructions
Alternatively, if you don't want to run webui.bat, here are instructions for installing
everything by hand:
2022-08-22 14:15:46 +00:00
2022-08-31 08:04:19 +00:00
```commandline
2022-08-31 08:10:46 +00:00
:: crate a directory somewhere for stable diffusion and open cmd in it;
:: make sure you are in the right directory; the command must output the directory you chose
2022-08-31 08:04:19 +00:00
echo %cd%
2022-08-22 14:15:46 +00:00
2022-08-31 08:04:19 +00:00
:: 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
2022-08-22 14:15:46 +00:00
2022-08-31 08:04:19 +00:00
:: 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())"
2022-08-22 14:15:46 +00:00
2022-08-31 08:04:19 +00:00
:: clone Stable Diffusion repositories
git clone https://github.com/CompVis/stable-diffusion.git
git clone https://github.com/CompVis/taming-transformers
2022-08-22 14:15:46 +00:00
2022-08-31 08:04:19 +00:00
:: install requirements of Stable Diffusion
pip install transformers==4.19.2 diffusers invisible-watermark
2022-08-22 14:15:46 +00:00
2022-08-31 08:04:19 +00:00
:: install k-diffusion
pip install git+https://github.com/crowsonkb/k-diffusion.git
2022-08-22 14:15:46 +00:00
2022-08-31 08:04:19 +00:00
:: (optional) install GFPGAN to fix faces
pip install git+https://github.com/TencentARC/GFPGAN.git
2022-08-22 14:15:46 +00:00
2022-08-31 08:04:19 +00:00
:: go into stable diffusion's repo directory
cd stable-diffusion
2022-08-22 14:15:46 +00:00
2022-08-31 08:04:19 +00:00
:: clone web ui
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
2022-08-22 14:15:46 +00:00
2022-08-31 08:04:19 +00:00
:: install requirements of web ui
pip install -r stable-diffusion-webui/requirements.txt
2022-08-22 14:15:46 +00:00
2022-09-01 10:32:34 +00:00
:: update numpy to latest version
pip install -U numpy
2022-08-31 08:04:19 +00:00
:: (outside of command line) put stable diffusion model into models/ldm/stable-diffusion-v1/model.ckpt; you'll have
:: to create one missing directory;
:: the command below must output something like: 1 File(s) 4,265,380,512 bytes
dir models\ldm\stable-diffusion-v1\model.ckpt
2022-08-22 14:15:46 +00:00
2022-08-31 08:04:19 +00:00
:: (outside of command line) put the GFPGAN model into same directory as webui script
:: the command below must output something like: 1 File(s) 348,632,874 bytes
dir stable-diffusion-webui\GFPGANv1.3.pth
```
After that the installation is finished.
Run the command to start web ui:
```
python stable-diffusion-webui/webui.py
```
2022-09-01 08:41:42 +00:00
If you have a 4GB video card, run the command with either `--lowvram` or `--medvram` argument:
2022-08-31 08:04:19 +00:00
```
2022-09-01 08:41:42 +00:00
python stable-diffusion-webui/webui.py --medvram
2022-08-31 08:04:19 +00:00
```
2022-08-22 14:15:46 +00:00
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.
2022-08-23 08:58:50 +00:00
2022-09-01 22:56:46 +00:00
2022-09-05 07:41:01 +00:00
### What options to use for low VRAM videocards?
2022-09-01 22:56:46 +00:00
- If you have 4GB VRAM and want to make 512x512 (or maybe up to 640x640) images, use `--medvram` .
2022-09-04 22:43:37 +00:00
- If you have 4GB VRAM and want to make 512x512 images, but you get an out of memory error with `--medvram` , use `--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` instead.
2022-09-01 22:56:46 +00:00
- If you have 4GB VRAM and want to make images larger than you can with `--medvram` , use `--lowvram` .
- If you have more VRAM and want to make larger images than you can usually make, use `--medvram` . You can use `--lowvram`
also but the effect will likely be barely noticeable.
- Otherwise, do not use any of those.
Extra: if you get a green screen instead of generated pictures, you have a card that doesn't support half
precision floating point numbers. You must use `--precision full --no-half` in addition to other flags,
and the model will take much more space in VRAM.
2022-09-04 16:09:00 +00:00
## Credits
- Stable Diffusion - https://github.com/CompVis/stable-diffusion, https://github.com/CompVis/taming-transformers
- k-diffusion - https://github.com/crowsonkb/k-diffusion.git
- GFPGAN - https://github.com/TencentARC/GFPGAN.git
- ESRGAN - https://github.com/xinntao/ESRGAN
2022-09-04 22:43:37 +00:00
- Ideas for optimizations and some code (from users) - https://github.com/basujindal/stable-diffusion
2022-09-04 16:09:00 +00:00
- Idea for SD upscale - https://github.com/jquesnelle/txt2imghd
- Initial Gradio script - posted on 4chan by an Anonymous user. Thank you Anonymous user.
- (You)