Best & Easiest Way to Run Stable Diffusion for Free (WebUI)

Generating Batches of Images with StableDiffusion WebUI
[Generating 9 Batches of Images] Prompt: “hyperrealistic portrait of a cyberpunk man, medium hair, confident, cybernetics, immersed within a network, by Guy Denning, Derek Gores, Russ Mills, glitch art, hyper focus, fined detail, polished, complex, hacking effects, holographic, digital tech effects, color blocking!, green, realistic, acrylic on canvas, concept art, abstract, 8k. trending on cgsociety, trending on artstation”

Stable Diffusion is among the best AI art generators at the time of writing. It generates fantastic art, it has relatively low hardware requirements, and it’s fast. One of the best things about it is that it’s also available as free and open-source.

Thanks to Stable Diffusion being open-source, it can be integrated it into your own projects. Whether you want to use it as a standalone AI art generator, or as part of a larger AI art project, it’s easy to set up and use.

This has lead to users finding all sorts of interesting ways to use Stable Diffusion. This is excellent news, as it means that the software is constantly evolving and improving. As more people use it, and more ideas are shared, the software just gets better and better.

One of these projects is Stable Diffusion WebUI, which allows us to use Stable Diffusion, on our computer or via Google Colab1Google Colab is a cloud-based Jupyter Notebook. Jupyter Notebooks are, in simple terms, interactive coding environments. Think of them as documents that allow you to write and execute code all in one place.

Google Colab is a service that provides free Jupyter Notebooks that are run on Google’s servers. This means that you can use Google Colab to write and execute code without having to download or install anything on your own computer.

Google Colab is a great tool for data scientists and machine learning engineers as it allows you to prototype and experiment with your code in a fast and convenient way. Additionally, Colab is perfect for sharing your work with others, as you can simply share the link to your notebook and anyone can view and execute the code.
, using an intuitive web interface with many interesting and time saving options and features, allowing us to continuously experiment with creating AI generated images for free.

In this tutorial we’ll cover what is, in my opinion, the best way to run Stable Diffusion for free. We’ll set up and run Stable Diffusion WebUI on Google Colab, so we can generate AI art no matter our computer’s hardware.

Basically you can create hundreds of images per day for free, and they’ll all be stored in our Google Drive. This is invaluable, especially considering that a prompt won’t always result in the perfect image right away, and you may have to keep on experimenting.

Here’s a quick view of how it looks like:

The reasons I consider this method to be the best are:

  1. It’s free.
  2. You’re running it in Google Colab. This means you don’t need to worry about your hardware. You can even run it from your phone.
    • You can also run it locally, on your computer. Install instructions are available for Linux and Windows. I have an NVIDIA 1660 SUPER and a 512x512px image takes ~2 minutes 3 seconds, vs 15-20s on Google Colab with an NVIDIA Tesla T4 or P100.
  3. The setup is easy and beginner friendly. Even though we’re using Google Colab to run it, it’s not complicated. You’ll just run a few initial steps, wait ~10 minutes, and then use Stable Diffusion from a very nice web interface.
  4. It has an easy to use and intuitive web interface, that you can access from your browser, and it has lots of features.
  5. It offers some very cool extra features such as:
    • Upscaling and face correction. It comes with two popular algorithms, to upscale images (increase their resolution), and to fix distorted faces (because Stable Diffusion may slightly distort some faces). The upscaling is done using ESRGAN and the restoration is done using GFPGAN.
    • The ability to write multiple prompts separated by |, and the system will create an image for each of them.
    • You can check out more info and features in its Github page.

Quick Video Demo

This is a video demonstrating how to set up Stable Diffusion WebUI from start to finish. The whole process pretty straightforward, and the only drawback is that we have to wait ~15 minutes for everything to be set up.

The video doesn’t show the fact that you also have to download the Stable Diffusion model (4GB in size) and upload it into your Google Drive. This may add to the waiting time, depending on your internet speed.

1. Open & Copy the Stable Diffusion WebUI Notebook

First we’ll copy the Google Colab Notebook to our Google Drive. This works like any other Google Doc.

  1. First access the Stable Diffusion WebUI Colab notebook here: https://colab.research.google.com/github/altryne/sd-webui-colab/blob/main/Stable_Diffusion_WebUi_Altryne.ipynb
  2. Then click on Copy to Drive. A new tab should open with our copy of Stabel Diffusion WebUI. You can close the old tab.
    Screenshot of the Stable Diffusion WebUI Notebook with 'Copy to Drive' highlighted

2. Check GPU Status

To use models like Stable Diffusion we need a GPU. Google Colab automatically allocates us a GPU, however we should make sure that our notebook is also set to use a GPU (and not a CPU).

To do this:

  1. Go in the menu, to Runtime > Change runtime typeScreenshot of Google Colab - Runtime > Change Runtime Type
  2. A small window will pop up. Make Hardware accelerator is set to GPUScreenshot of Google Colab - Menu > Runtime > Change runtime type - Hardware Accelerator is Set to GPU

3. Download the Stable Diffusion Model File & Upload to Google Drive

The Stable Diffusion model file is a .ckpt file.

You’ll also see the .ckpt file referred to as the Weights or Weights and Biases. A model is simply a collection of weights and biases, so a .ckpt file is effectively a model file.

Create an Account on HuggingFace.co

To be able to download the Stable Diffusion model we’ll need an account on HuggingFace.co, where the model is hosted.

The sign-up process is simple and straightforward. Just sign up here and confirm your account: https://huggingface.co/join

Request Access to the Stable Diffusion Repository

When you’re logged into your HuggingFace account, visit this URL https://huggingface.co/CompVis/stable-diffusion-v-1-4-original.

We’ll need to check a box saying that we accept the terms that will allow us to download the Stable Diffusion model.

Agree and Access Hugging Face Repository
Agree to Terms and Access Hugging Face Repository

Method 1: Download/Upload Weights Manually (Slower)

Using this method we’ll download the Stable Diffusion weights using our browser, as we’d download any other file. Then we’ll upload to the file from our computer to Google Drive.

This method is more user friendly, but it’s slower.

  1. Download the Stable Diffusion model. To do this visit https://huggingface.co/CompVis/stable-diffusion-v-1-4-original and click on sd-v1-4.ckpt to download it. It’s roughly 4GB in size.
    Screenshot of the Stable Diffusion model download page
    1. Download the Stable Diffusion Model (Weights & Biases) File
  2. Upload the file in our Google Drive, in My Drive > AI > models directory. If they don’t already exist, then created them yourself.
    Screenshot of the Stable Diffusion model in Google Drive
    2. Upload the sd-v1-4.ckpt file in your Google Drive in My Drive > AI > models.

Method 2: Download Weights Directly into Google Drive (Faster)

If this method seems complicated, feel free to use Method 1. No need to complicate things if it seems like it will be a hassle.

Using this method we’ll download the Stable Diffusion weights from our Google Colab, using the cURL utility, and place it directly into the required directory in our Google Drive.

1. Create a User Access Token

For this to work, we’ll also need to generate an access token that we’ll use to authenticate when using cURL. This is because we need some form of authentication when downloading the model.

To do this:

  1. Go to your account Settings > Access Tokens. Alternatively you can directly go to this URL https://huggingface.co/settings/tokens.
  2. Click on New token
    Create New Token
  3. Name your token. It can be anything you’d like. It’s only for reference purposes. You can leave Role: read. Click Generate a token.
    Generate a token

2. Mount Google Drive to the Stable Diffusion WebUI Notebook

Next we’ll need to mount (connect) Google Drive in our Colab notebook.

We’ll have to do this later anyway, because the Stable Diffusion WebUI setup requires us to. But if we’ll mount Google Drive now, so we don’t have to worry about the download later on.

To do this we’ll have to run the following code anywhere in the notebook:

Mount Google Drive
from google.colab import drive
drive.mount('/content/drive')

To do this click on the + Code button near the top left of the notebook, and a code cell will appear. Just paste the above two lines in that cell, and click the play button at its left.

You’ll be prompted if you want to connect to Google Drive, and after that small window will pop up where you select the account you want to connect with, and to allow some permissions.

Popup in Colab Asking if You Want to Connect to Google Drive

3. Download the Stable Diffusion Model via cURL

Now that Google Drive is connected, click the + Code button again, to add another code cell, and paste in the following two lines:

!mkdir -p /content/drive/MyDrive/AI/models/
!curl -L https://huggingface.co/CompVis/stable-diffusion-v-1-4-original/resolve/main/sd-v1-4.ckpt --output "/content/drive/MyDrive/AI/models/sd-v1-4.ckpt" -H "Authorization: Bearer YOUR_ACCESS_TOKEN"

You’ll have to replace the YOUR_ACCESS_TOKEN with an access token from your HuggingFace account.

What those two lines do is:

  1. !mkdir -p /content/drive/MyDrive/AI/models/ will create the necessary directories in your Google Drive.
  2. The second line will use curl to download the sd-v1-4.ckpt file, and it will save it in the folder we just created. The -H "Authorization: Bearer YOUR_ACCESS_TOKEN" is so HuggingFace allows us to download the file. If this part isn’t correct we won’t be able to download the file using this method.

Here’s how my notebook looks like after I’ve mounted Google Drive and downloaded sd-v1-4.ckpt via curl.

Download Stable Diffusion via cURL 2

This method may be a little bit more intimidating to someone new to Google Colab, but it’s considerably faster than downloading the model to your local computer and then uploading it.

4. Run All

Now that all the prerequisites are set up, we can go to Runtime > Run All.

This will run all the cells in the notebook in order and we’ll need to wait for the notebook to finish setting up.

Screenshot of Google Colab -> Runtime > Run All

Important: After about 8 minutes you’ll likely be asked to Connect to Google Drive. So keep a look out for that, because you’ll need to allow the connection.

Popup in Colab Asking if You Want to Connect to Google Drive

5. Open the Stable Diffusion Web User Interface

While you wait for everything to load, click the little arrow next to 3 - Launch WebUI for stable diffusion because that’s where we’ll see the URL for the Stable Diffusion WebUI, when everything is ready.

Google Colab Screenshot - Expand Launch WebUI
The notebook also shows us a screenshot of how to expect the WebUI URL to look like.

When it’s finished it should look something like this. As you can see, the URL generated for me is https://16883.gradio.app. The URL will be different each time you run this notebook.

Run StableDiffusion WebUI

When you access your URL, you’ll see the Stable Diffusion WebUI.

Stable Diffusion WebUI

Important: You need to keep the Google Colab running. If you close it, then the user interface will stop working.

6. Generate Images using Stable Diffusion WebUI

The basic usage is to just input a prompt and click Generate.

Stable Diffusion WebUI comes with multiple options to generate images, such as generating multiple batches, or multiple images in one batch, changing dimensions, and more.

You can check out some more about these features in the Features section of the original Github repository for Stable Diffusion WebUI.

Here are some examples of me using the different features of Stable Diffusion Web UI:

Where Are Images Saved

The images generated with Stable Diffusion WebUI are saved in our Google Drive:

  1. In My Drive > AI > StableDiffusion there will be an image saved for time you run image generation. If you generate multiple images in one run, and have left it enabled to generate an image grid of all the resulting images, then you’ll see the image grid in this directory.
    Google Drive MyDrive > AI > StableDiffusion Directory
    Google Drive MyDrive > AI > StableDiffusion Directory
  2. In My Drive > AI > StableDiffusion > samples is where you’ll have a directory for every prompt you’ve run, and in this directory there will be all the images created from that prompt, as well as a .yaml file with the settings you used (prompt, height, steps, seed, etc), which is very useful.
    Google Drive MyDrive > AI > StableDiffusion > Samples Directory

Checking Stable Diffusion Image Generation Progress

From what I’m seeing, the loading graphic from the user interface is not very accurate. The best way to check image generation progress is back in the Google Colab.

Checking Stable Diffusion WebUI Image Generation Progress
Checking Image Generation Progress

Troubleshooting

FileNotFoundError: [Errno 2] No such file or directory: ‘/content/drive/MyDrive/AI/models/sd-v1-4.ckpt’

This happens when the notebook is trying to look for the Stable Diffusion model file in the /content/drive/MyDrive/AI/models directory, but doesn’t find it.

This can happen if:

  • you have forgotten to download the model file and place it in that directory
  • the directory name doesn’t match, such as if it’s called /AI/Models instead of /ai/models
Screenshot of "FileNotFoundError: [Errno 2] No such file or directory: '/content/drive/MyDrive/AI/models/sd-v1-4.ckpt'"
FileNotFoundError: [Errno 2] No such file or directory: ‘/content/drive/MyDrive/AI/models/sd-v1-4.ckpt’

Useful Resources

Conclusion

In this tutorial we covered how to set up Stable Diffusion WebUI to create AI generated art using an intuitive web interface. As mentioned before, the WebUI offers you multiple useful and interesting features, and we recommend you check the original Github repository for more information on each of them.

With Stable Diffusion WebUI you’ll be able to have fun easily generating hundreds of images, to be sure you generate the right one for your prompt. You’ll conveniently have them stored in your Google Drive, and each image will have its’ settings stored in a .yaml file so you can share your settings, or tweak your settings and regenerate the image at a later date.

With ESRGAN you can upscale your images up to 4 times, and with GFPGAN you can fix distorted portraits. It also comes with with the Image-to-Image feature, where you can upload/draw an initial image to help guide Stable Diffusion to the desired result.

If you encountered any issues or have any questions, please feel free to leave a comment and we’ll get back to you as soon as possible.

  • 1
    Google Colab is a cloud-based Jupyter Notebook. Jupyter Notebooks are, in simple terms, interactive coding environments. Think of them as documents that allow you to write and execute code all in one place.

    Google Colab is a service that provides free Jupyter Notebooks that are run on Google’s servers. This means that you can use Google Colab to write and execute code without having to download or install anything on your own computer.

    Google Colab is a great tool for data scientists and machine learning engineers as it allows you to prototype and experiment with your code in a fast and convenient way. Additionally, Colab is perfect for sharing your work with others, as you can simply share the link to your notebook and anyone can view and execute the code.
1 Shares:
Subscribe
Notify of
guest
Receive notifications when your comment receives a reply. (Optional)
Your username will link to your website. (Optional)

37 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Michael E
Michael E
8 days ago

You can also run with no setup at canva, see texttoimage.app

chibi_panda
chibi_panda
8 days ago

is it possible to host a persistent version of the webui on the huggingface spaces as it says?

Said S.
Said S.
6 days ago

you have forgotten to download the model file and place it in that directory

I did this but it’s not working, I created a folder called AI and a folder called models inside that folder and put the file inside that called sd-v1-4.ckpt.

the directory name doesn’t match, such as if it’s called /AI/Models instead of /ai/models

I did AI/models just as this tutorial but I still have this error.

What did I do wrong?

Tomer
Tomer
3 days ago
Reply to  EdXD

I get the same kind of error:
FileNotFoundError: [Errno 2] No such file or directory: ‘/content/models/sd-v1-4.ckpt’
I attached the error and my drive folder.
https://ibb.co/ZfJbbmD

2022-09-19 15.44.10 colab.research.google.com 590b5c0b1e1b.png
Tomer
Tomer
3 days ago
Reply to  EdXD

It is checked, it even asks for permission to access google drive as your instructions state. Still, it gives this error for some reason.

2022-09-20 08.21.21 colab.research.google.com 4e7c0f1370f8.png
Tomer
Tomer
3 days ago
Reply to  EdXD

It is checked (even asks for GDrive permission) and I still receive the error

2022-09-20 08.21.21 colab.research.google.com 4e7c0f1370f8.png
Andrew
Andrew
5 days ago

Thank you for this fantastic guide! As someone who struggled briefly with Method 2: Step 3, I just want to mention, in case it’s helpful, that there appears to be a subtle autocorrect in the given code that causes an error when it’s copied verbatim. In the second line where it currently says “– output”, I believe it should be “–output”. I’m sure that this is merely a word-processing glitch, but hopefully a note here helps save any future head-scratching

Bardic
Bardic
5 days ago

Thanks for the helpful tutorial. A couple of points/questions:

1) I think there’s a typo in the code box:

!curl -L https://huggingface.co/CompVis/stable-diffusion-v-1-4-original/resolve/main/sd-v1-4.ckpt – output "/content/drive/MyDrive/AI/models/sd-v1-4.ckpt" -H "Authorization: Bearer YOUR_ACCESS_TOKEN"

When I try to run this, it suggests that ‘– output’ is required rather than with just one dash.

2) I’m a total noob at this stuff, so probably a noob question: do I have to run the whole script each time I want to start using it, including the setup stage? It seems like it from my testing so far, but that seems counterintuitive to this noob, so maybe I’m missing something.

3) I’m running into an issue where the finished images aren’t showing up in the WebUI if I choose a batch number of higher than one. The processing finishes, which I can see on the Colab page, and the generated images show up in my Google Drive, but the image (and output) panes of the WebUI just keep on showing their ‘loading/working’ animation indefinitely. If I reload the page and turn the batch back down to 1, it works again. Any idea what I’m doing wrong?

Thanks again!

Jadrian
Jadrian
3 days ago
Reply to  Bardic

I, too, am seeing a bug where images fail to appear, but this is usually when I try upscaling. The first upscale works fine, but all subsequent upscales fail to load the resulting image, and also keep the Colab session resources marked as endlessly “Busy”.

Bardic
Bardic
5 days ago

…and now I think I know why the code I mentioned in 1) is messed up: this site software seems to be automatically converting two dashes into one, which also happened in my comment. 😛

To spell it out, then: the script seems to want two dashes in front of ‘output’, and there’s only one in front of it in the code block.

HekFar
HekFar
4 days ago

Hi EdXD,
My issue is that I wanted to upload the full ema checkpoint, after I uploaded to my google drive, I change the code in step 3 to –ckpt ‘{models_path}/sd-v1-4-full-ema.ckpt’ \
the screenshot shows that it stops running after “eps-prediction mode” leaving a ^C
and never loads the url for UI. Is it possible to use the full-ema.ckpt? If so could you help me fix the code to reflect the proper path?

Screenshot 2022-09-18 174844.png
Mr-J-Photoshooting
4 days ago

Thanks for this tuto, it seems the part where you need to add code to mount and download models aren’t necessary anymore, there is a part in the note book where you only need to put your token.

I’m still getting familiar with it, less convenient than the set-up i used before (but at least i don’t kill my computer^^) . Main issue is, when images are finished to be generated, the ui don’t show images, and seems to still be running, even in i see in notebook that nothing is running anymore. So between each generation i need to reload the page.

Mr-J-Photoshooting
3 days ago

Ok so it seems i can’t use it any more, i didn’t change anything, but when i tried to launch it to start a new creation session, i got this, i don’t find any way to start the notebook
No CUDA GPUs are available

Look like, notebook solution isn’t so free, google ask us to pay to be able to run it as we want i think.

Billions
Billions
3 days ago

Hey, great, easy to follow instructions! I got it working, but you have a little error in the curl function block in Method 2, step 3 where you have ” – output”
when it should be “–output”

Aside from that, my results are generally slower and less accurate than what I’m getting from Huggingface’s SD demo and even the Dawn AI app for ios. maybe it’s a GPU limitation of using colab or some setting that I have yet to properly tweak. also haven’t been able to get img2img working.
Anyway, I hope my little note helps some other noobs like myself.
Thanks!

Lucas E
Lucas E
3 days ago

I’m getting an error in Google collab during the final step,. I don’t really know how to address this, I’m a pleb!

This is the error it spits:

ImportError: this version of pandas is incompatible with numpy < 1.20.3
your numpy version is 1.19.2.
Please upgrade numpy to >= 1.20.3 to use this pandas version

TheUntrainedEye
TheUntrainedEye
1 day ago
Reply to  EdXD

I’m just commenting to say that I’m also running into this problem. And when I run “%pip install numpy” I get toldRequirement already satisfied: numpy in /usr/local/lib/python3.8/site-packages (1.23.3)
, while when I run “import numpyprint(numpy.version.version)” I get told 1.21.6, which only confuses me even more. I think though that the install package *is* only installing numpy 1.19.2, judging by how in the “1.1 Download repo and install” step has this in its output:Package numpy-base conflicts for:numpy-basemkl_fft -> numpy[version=’>=1.16, numpy-base==1.19.2[build=’py38hfa32c7d_0|py38h4c65ebe_1′]numpy -> numpy-base==1.19.2[build=’py38hfa32c7d_0|py38h4c65ebe_1′]torchvision -> numpy[version=’>=1.11′] -> numpy-base==1.19.2[build=’py38hfa32c7d_0|py38h4c65ebe_1′]mkl_random -> numpy[version=’>=1.16, numpy-base==1.19.2[build=’py38hfa32c7d_0|py38h4c65ebe_1′]
andPackage libgfortran-ng conflicts for:libgfortran-ngnumpy -> numpy-base==1.19.2=py38h4c65ebe_1 -> libgfortran-ngnumpy-base -> libgfortran-ng
This suggests that the error isn’t imaginary, the published version of the notebook really is only installing Numpy 1.19.2.

dispari
dispari
1 hour ago
Reply to  EdXD

Same here :-/

jonathan
jonathan
1 hour ago
Reply to  Lucas E

Did you manage to solve the problem of: Import: this version offer pandas is incompatible with numpy <1.20.3 ??? I am going crazy !!!
Your numpy version IS 1.19.2.
PLEASE UPGRESS NUMPY TO> = 1.20.3 TO US THIS PANDAS VERSION

jonathan
jonathan
22 minutes ago
Reply to  EdXD

perfect, it worked thank you very much, you have saved my life

Jadrian
Jadrian
3 days ago

Joining in with some other comments with a bit of findings. It seems the upscale functionality may have a bug of some kind. It works to upscale one image after loading up the Colab, but then fails to upscale others. I can see that the Colab session shows as busy when this is happening, as though there is still an upscale process running amok on the GPU session. I haven’t yet figured out what is holding up that process or how to move beyond it, but wanted to chime in that I am experiencing it, too. What a fantastic write-up, though, thanks for helping me get this running!

dispari
dispari
21 minutes ago

Hello, there is a way to stop batch processing once it is started (for corrections in prompt etc)?

Blue_Lotus
Blue_Lotus
14 minutes ago

OMG this might as well be written in Russian. I can’t even get the file to upload to drive!
All I want to do is make pretty art and not need to be some sort of code reading genius

You May Also Like