This guide provides instructions on how to set up and host your own image generation model using Automatic1111's Stable Diffusion WebUI.
- Operating System: Windows/Linux/Mac
- GPU: Either your system has a dedicated NVIDIA GPU with at least 8GB VRAM (higher VRAM recommended for larger models) OR you know how to get access to a virtual machine with similar specs (either through Google Cloud or runpod)
- The A1111's repo has installation guide if you have an AMD or Intel GPU, but I have not tested those steps yet. We will be using the instructions for NVIDIA GPUs for this workshop.
- Drivers: Ensure you have the latest NVIDIA drivers installed
- Some Other Requirements:
- Python 3.10.6 (if you have an older or newer Python version, you will need to uninstall and then reinstall this version)
- Git
- CUDA, since we will be focusing on NIVDIA GPUs
This is how I do it on both Windows and Linux. The A1111's repo has very detailed instructions on how to install on different operating systems.
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.gitcd stable-diffusion-webui- Download a Stable Diffusion model (e.g., 3.0, SDXL) from huggingface.
- Place the
.safetensorsfile in themodels/Stable-diffusiondirectory. - Experiment with different model sizes to figure out what works best for your setup!
To start the server, navigate into the directory, then use:
./webui.sh --listen # For Linux/Mac
webui-user.bat # For Windows-
By default, the WebUI runs on http://localhost:7860
-
To make it accessible over your network, add the
--listenflag:./webui.sh --listen
-
You can also configure other parameters inn the
webui-user.batfile for Windows, orwebui-user.shfile for Linux. -
My prefered commandline arguments for NVIDIA GPUs:
--device-id=0 --port [whatever OPEN port number you prefer] --no-half-vae --xformers --listen --api
- Generate with whatever prompts you would like!
- Experiment with the different parameters in the UI!
- With the
--apitag, you can read the API documentations at the/docssubdirectory (i.e.localhost:7860/docs); or you can also click theAPIlink at the bottom of the web UI. - In your scripts, send requests to the
/sdapi/v1/txt2imgendpoint. - For example, if you web UI is hosted at the default port 7860, you would point your requests to
http://localhost:7860/sdapi/v1/txt2imgwith the appropriate json payload for parameters. - See
generate.pyfor an example (thanks Dr. Maiti for letting me steal your code) - Before running the script, make sure you have:
- A working Python environment (which you should already have if you are able to run the web ui)
- The following Python packages:
requestsPillow
- You can install these packages using
pippip install requests Pillow