Creating fun AI art is something that we all discovered recently. DALL E 2 really impressed us, and then DALL E Mini made us laugh (and have nightmares). Stable Diffusion has now entered the arena and has proven itself to be a fantastic AI that will create beautiful art for your text-based queries.
To do this, we will be using the instructions found at https://github.com/sd-webui/stable-diffusion-webui/wiki/Installation
Please note that you will need to set up a https://huggingface.co/ account for this tutorial to work.
Table of Contents
- Why Install Stable Diffusion – I can just use it online.
- Step by-step Installation guide for Windows
- Running webui,cmd for the first time
- Credit
Why Install Stable Diffusion – I can just use it online.
There are many reasons to run an AI model for yourself. The first is that there is something pretty neat about learning how to install your own AI model and then run it on your computer.
Another benefit is that we are taking the strain off of the main website that is out there on the internet. This means that the overall experience for everyone will improve as more people install these models on their local machines.
Step by-step Installation guide for Windows
- Install Git & Miniconda :
Here is the app you need to get started https://gitforwindows.org/ . It offers all default settings except that of the default editor. Download it, and accept all of the default settings it offers. Most people who don’t know what to choose as their default editor should choose Notepad since everyone has VIM on their computer.
Next, download MiniConda3 from https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe
Install the application and then run it.
Now Open Anaconda Prompt.
Let’s clone the repo so we can run the AI image generator
We do this by typing in git clone https://github.com/sd-webui/stable-diffusion-webui.git into the prompt.
This will create the stable-diffusion-webui directory in your Windows user folder.
Your screen should look something like this:
Once a repo has been cloned, updating it is as easy as typing git pull inside of Miniconda when in the repo’s topmost directory downloaded by the clone command. Below you can see I used the cd command to navigate into that folder.
- Create an account on Hugging Face: https://huggingface.co/ if you haven’t already
- Go to this link and click Authorize after signing up and being logged in: https://huggingface.co/CompVis/stable-diffusion-v-1-4-original
- After you have authorized your account, you will be able to download the model weights for version 1.4 of the model by clicking on this link. Future versions will be released in the same way, and updating them will be the same process: https://huggingface.co/CompVis/stable-diffusion-v-1-4-original/resolve/main/sd-v1-4.ckpt
- You’re looking at a download that’s around 4GB in size. Download the model into this directory: C:\Users\<username>\stable-diffusion-webui\models\ldm\stable-diffusion-v1
- Rename sd-v1-4.ckpt to model.ckpt once it is inside the stable-diffusion-v1 folder.
- The next step in creating the environment Stable Diffusion needs is to create our stable-diffusion-webui folder in Miniconda.
- (Optional) If you already have an environment named ldm set up for an installation of Stable Diffusion, open the environment.yaml file in /stable-diffusion-webui/ and change ldm to ldo.
Running webui,cmd for the first time
- You will always run webui.cmd in the root folder (/stable-diffusion-webui/). It has the functions to automatically do the followings:
- Create a conda env
- Install and update requirements
- Run the relauncher and webui.py script for gradio UI options
- Run webui.cmd by double clicking the file.
- Wait for it to process, this could take some time. Eventually it’ll look like this:
And
- You’ll receive warning messages on GFPGAN, RealESRGAN and LDSR but these are optionals and will be further explained below.
- You will have to wait for this process to finish. Afterwards you can now go to your web browser and open the link to http://localhost:7860/.
- Enter the text prompt required and click generate.
- You should be able to see progress in your webui.cmd window. The http://localhost:7860/ will be automatically updated to show the final image once progress reach 100%
- Images created with the web interface will be saved to \stable-diffusion-webui\outputs\ in their respective folders alongside .yaml text files with all of the details of your prompts for easy referencing later. Images will also be saved with their seed and numbered so that they can be cross referenced with their .yaml files easily.
- You’ll receive warning messages on GFPGAN, RealESRGAN and LDSR but these are optionals and will be further explained below.
- In the meantime, you can now go to your web browser and open the link to http://localhost:7860/.
- Enter the text prompt required and click generate.
- You should be able to see progress in your webui.cmd window. The http://localhost:7860/ will be automatically updated to show the final image once progress reach 100%
- Images created with the web interface will be saved to \stable-diffusion-webui\outputs\ in their respective folders alongside .yaml text files with all of the details of your prompts for easy referencing later. Images will also be saved with their seed and numbered so that they can be cross referenced with their .yaml files easily.
Optional additional models
There are three more models that we need to download in order to get the most out of the functionality offered by sd-webui.
GFPGAN
- If you want to use GFPGAN to improve generated faces, you need to install it separately.
- Download GFPGANv1.3.pth and put it into the /stable-diffusion-webui/src/gfpgan/experiments/pretrained_models directory.
RealESRGAN
- Download RealESRGAN_x4plus.pth and RealESRGAN_x4plus_anime_6B.pth.
- Put them into the stable-diffusion-webui/src/realesrgan/experiments/pretrained_models directory.
LDSR
- Detailed instructions here. Brief instruction as follows.
- Git clone Hafiidz/latent-diffusion into your /stable-diffusion-webui/src/ folder.
- Run /stable-diffusion-webui/src/latent-diffusion/download_model.bat to automatically download and rename the models.
- Wait until it is done and you can confirm by confirming two new files in stable-diffusion-webui/src/latent-diffusion/experiments/pretrained_models/
- (Optional) If there are no files there, you can manually download LDSR project.yaml and model last.cpkt.
- Rename last.ckpt to model.ckpt and place both under stable-diffusion-webui/src/latent-diffusion/experiments/pretrained_models/.
- Refer to here for any issue.