Python AI painting
In this article, we will introduce how to build your own AI drawing tool based on some open source libraries.
The open source library to be used is Stable Diffusion web UI, which is a Stable Diffusion browser interface based on the Gradio library
Stable Diffusion web UI GitHub 地址:GitHub - AUTOMATIC1111/stable-diffusion-webui: Stable Diffusion web UI
Running Stable Diffusion requires relatively high hardware requirements, and it will consume a lot of resources when running, especially the graphics card.
Windows environment installation
The local environment requires Python 3.10.6 or above to be installed and added to the local environment variables.
Download Stable Diffusion web UI GitHub source code GitHub - AUTOMATIC1111/stable-diffusion-webui: Stable Diffusion web UI .
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
If Git is not installed, you can download the zip archive in the upper right corner.
Unzip stable-diffusion-webui and enter the stable-diffusion-webui directory.
Next we need to download the model, download address: https://huggingface.co/CompVis/stable-diffusion-v-1-4-original
Move the downloaded model to the stable-diffusion-webui/models/Stable-diffusion directory.
Enter the stable-diffusion-webui directory:
Windows run as non-administrator:
webui-user.bat
Linux and Mac OS environments execute the following commands:
./webui.sh
Next, the program will be automatically installed and started. If the startup is successful, you will see an accessible URL address http://127.0.0.1:7860:
Visit http://127.0.0.1:7860, the interface is as follows:
Note: If the installation is stuck, it is likely that there is a problem with downloading the Github source code. You can use some Github mirrors to solve it. There is no very stable mirror at present. It is recommended to search on Google. I use the following mirror address https://hub.fgit.ml on April 6, 2023, open the launch.py file in the stable-diffusion-webui directory, and replace the Github address of the following part of the code (the code is about 230~ 240 lines):
Introduction to Civitai
Civitai has many customized models, and they can be downloaded for free. We use the Guofeng 3 model for testing. Download address: https://civitai.com/models/10415/3-guofeng3?modelVersionId=36644
After downloading, we move the model to the stable-diffusion-webui/models/Stable-diffusion directory and restart stable-diffusion-webui:
./webui.sh
In this way, we can select the Guofeng 3 model in the model list :
After selection, we can go to the model introduction page to copy some prompt words and test parameters:
In order to generate quickly, I halved the height and width, and then click the generate button: