Ready to Dive into Generative Image AI? How Developers Can Run Stable Diffusion on Their Own Computers in 3 Steps
AI is revolutionizing the landscape of what's possible for solo devs.
I've known this for a while, yet have resisted the wave. I mostly felt like it was just hype but the more I play around with it, the more I realize how much I REALLY need to get involved. I've done a bit with ChatGPT but have moved on to experimenting with generating images with AI.
I also like to run everything on my own home server like a real nerd 😅
With that context, I set out to figure out how to run some kind of image-generating AI solution on my server. After running through a few tutorials, I stumbled on Stable Diffusion. It's an open-source AI solution that can be run on any computer with enough power.
In this article, I'll walk through the three simple steps I took to get Stable Diffusion up and running on my Mac.
Install Homebrew and the dependencies
Homebrew is kind of the standard for managing packages on a Mac.
In fact, if you didn't have it installed yet, I'd be kind of surprised. There are a number of dependencies needed for Stable Diffusion to run locally. The following script is what you'd run in a terminal to install it:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Run the following command to install the necessary dependencies:
brew install cmake protobuf rust python@3.10 git wget
Install stable-diffusion-webui
Next, you'll need to clone the repository to run Stable Diffusion.
If you do any amount of research you'll find that there are quite a few options to do this. The one I tried that worked for me was the stable-diffusion-webui
repository.
Run the following command to clone the repo:
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
Now you'll need a model for Stable Diffusion to work with.
A model contains all of the info required by Stable Diffusion to generate stuff. Do enough digging around and you'll find there are quite a few models openly available. For this demo, download the model linked here: https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned.ckpt
Place it in the /models/Stable-diffusion
folder of the repository.
Generate something
Now open your terminal in the root of the project and run ./webui.sh --no-half
.
This starts the project up. It will take a while to get going because it does some setup during the first run. Once you see the following message, you should be good to go.
Running on local URL: http://127.0.0.1:7860
Enter that URL in your browser and you should be able to generate images!