How to Run Stable Diffusion: A Step-by-Step Guide

Published by askwalle.com

Learn how to use Stable Diffusion, an advanced open-source deep learning model that generates high-quality images from text descriptions. This tutorial covers the basics of how the model works and step-by-step instructions for running Stable Diffusion online and locally.

How To Run Stable Diffusion Online

If you wish to start using the Stable diffusion model immediately, you can run it online using the following tools.

1. DreamStudio

Stability AI, the creators of Stable Diffusion, have made it extremely simple for curious parties to test their text-to-image model with their online tool, DreamStudio.

DreamStudio grants users access to the latest version of Stable Diffusion models and allows them to generate an image in up to 15 seconds.

DreamStudio UI

DreamStudio user interface. Image source: DreamStudio.

When writing this tutorial, new users receive 100 free credits to try out DreamStudio, which is enough for 500 images using the default settings! Additional credits can be purchased within the application at your convenience, costing only $10.00 per 1000 credits.

2. Hugging Face

Hugging Face is an AI community and platform that promotes open-source contributions. Though it’s highly recognized for its transformer models, Hugging Face also provides access to the latest Stable diffusion model, and like a true lover of open-source, it’s free.

To run stable diffusion in Hugging Face, you can try one of the demos, such as the Stable Diffusion 2.1 demo.

The tradeoff with Hugging Face is that you can’t customize properties as you can in DreamStudio, and it takes noticeably longer to generate an image.

Hugging Face Stable Diffusion

Stable Diffusion demo in Hugging Face. Image by author.

How to Run Stable Diffusion Locally

But what if you want to experiment with Stable Diffusion on your local computer? We’ve got you covered.

Running Stable Diffusion locally enables you to experiment with various text inputs to generate images that are more tailored to your requirements. You may also fine-tune the model on your data to improve the results, given the inputs you provide.

Disclaimer: You must have a GPU to run Stable Diffusion locally.

Step 1: Install Python and Git

To run Stable Diffusion from your local computer, you will require Python 3.10.6. This can be installed from the official Python Website. If you get stuck, check out our How to Install Python tutorial.

Check the installation worked correctly by opening the command prompt, typing python, and executing the command. This should print the version of Python you’re using.

Disclaimer: The recommended version to run Stable Diffusion is Python 3.10.6. We recommend not to proceed without this version to avoid problems.

Next, you must install the code repository management system Git. The Git Install Tutorial can help, and our Introduction to Git course can deepen your knowledge of Git.

Step 2: Create a GitHub and Hugging Face account

GitHub is a software development hosting service where developers host their code so they can track and collaborate with other developers on projects. If you haven’t got a Github account, now is also a good time to create one—check out Github and Git Tutorial for Beginners for assistance.

Hugging Face, on the other hand, is an AI community that advocates for open-source contributions. It is the hub for several AI models from various domains, including natural language processing, computer vision, and more. You’ll need an account to download the latest version of Stable Diffusion. We will get to this step later.

Step 3: Clone Stable Diffusion Web-UI

In this step, you will download the Stable Diffusion Web-UI to your local computer. While it's helpful to create a dedicated folder (e.g., stable-diffusion-demo-project) for this purpose, it's not mandatory.

1. Open Git Bash:

  • Make sure you have Git Bash installed on your computer.

2. Navigate to your desired folder:

  • Open Git Bash and use the cd command to navigate to the folder where you want to clone the Stable Diffusion Web-UI. For example:
cd path/to/your/folderPowered By 

3. Clone the repository:

  • Run the following command to clone the Stable Diffusion Web-UI repository:
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
Powered By 

4. Verify the clone:

  • If the command executes successfully, you should see a new folder named stable-diffusion-webui in your chosen directory.

Install stable diffusion

Note: You can find more specific instructions for your hardware and operating system in the Stable Diffusion web UI Github repository.

Step 4: Download the latest Stable Diffusion model

1. Log in to Hugging Face:

2. Download the Stable Diffusion model:

3. Locate the model folder:

  • Navigate to the following folder on your computer: stable-diffusion-webui\models\Stable-diffusion

4. Move the downloaded model:

  • In the Stable-diffusion folder, you will see a text file named Put Stable Diffusion Checkpoints here.
  • Move the downloaded Stable Diffusion model file into this folder.

Step 5: Setup the Stable Diffusion web UI

In this step, you will install the necessary tools to run Stable Diffusion.

1. Open the Command Prompt or Terminal.

2. Navigate to the Stable Diffusion web UI folder:

  • Use the cd command to navigate to the stable-diffusion-webui folder you cloned earlier. For example:
cd path/to/stable-diffusion-webuiPowered By 

3. Run the setup script:

  • Once you are in the stable-diffusion-webui folder, run the following command:
webui-user.batPowered By 

This script will create a virtual environment and install all the required dependencies for running Stable Diffusion. The process may take about 10 minutes, so be patient.

Note: You can find more specific instructions for your hardware and operating system in the Stable Diffusion web UI Github repository.

Step 6: Run Stable Diffusion locally

After the dependencies have been installed, a URL will appear in your command prompt: http://127.0.0.1:7860.

  • Copy and paste this into your web browser to run the Stable Diffusion web UI.
  • Now, you can start running prompts and generating images!

Stable diffusion dashboard

Stable Diffusion web UI running locally. Image by author.

Conclusion

Stable Diffusion represents a significant advancement in the field of generative AI. It offers the ability to generate high-quality, detailed images from textual descriptions. Whether you are looking to modify existing images, enhance low-resolution images, or create entirely new visuals, Stable Diffusion provides a powerful and versatile toolset.

With the recent updates and improvements in Stable Diffusion 3 and Medium, the model's capabilities have been further enhanced, making it a leader in the generative AI space.

Running Stable Diffusion locally or through various online platforms like DreamStudio and Hugging Face allows you to explore and leverage its full potential. Following the steps outlined in this guide, you can set up and start using Stable Diffusion to meet your creative and practical needs!