AI Art for Beginners - Stable Diffusion Crash Course

Deep Learning Course - Level: Beginner

Automatic1111 & Stable Diffusion - Google Colab & Google Drive Setup


expand_more chevron_left


expand_more chevron_left

Google Colab Setup

For troubleshooting any issues with this Google Colab setup, please go to the DeepLizard Discord server and discuss the issue in the channel for this course.

It's important to note that Google Colab has restricted the use of the Automatic1111 UI under the free version. It's no longer possible at the moment to use the Automatic1111 UI with Google Colab for free.

The Colab product lead has said that the team cannot support the usage growth of the Automatic1111 UI and Stable Diffusion on their budget. This was mentioned in this tweet.

This section covers how to get Google Colab setup for this course. The general steps for getting Colab setup are as follows:

  1. Go to Google Colab
  2. Upload notebook: deeplizard-colab-automatic1111-ui.ipynb
  3. Configure GPU
  4. Download Automatic1111 Interface from GitHub
  5. Download Stable Diffusion from HuggingFace
  6. Connect to Google Drive
  7. Launch the Automatic1111 Stable Diffusion Web UI

Let's breakdown each of these steps.

The Notebook

A notebook for running the Automatic1111 interface as been included in the course resource files. Locate this notebook and upload it to Google Colab.

Configure Colab to use a GPU by choosing: Choose: Runtime > Change runtime type > Hardware accelerator > GPU

After configuring the GPU, run the Test GPU cell below:

# Test GPU

THe output should look something like this:

| NVIDIA-SMI 510.47.03    Driver Version: 510.47.03    CUDA Version: 11.6     |
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|   0  Tesla T4            Off  | 00000000:00:04.0 Off |                    0 |
| N/A   57C    P0    27W /  70W |      0MiB / 15360MiB |      0%      Default |
|                               |                      |                  N/A |
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|  No running processes found                                                 |

Next, we are ready to download the Automatic1111 UI.

Download Automatic1111 Interface

We are downloading the Automatic1111 interface from GitHub using the code below:

!pip install fastapi==0.90
!git clone
%cd stable-diffusion-webui/
!git checkout 2c1bb46c7ad5b4536f6587d327a03f0ff7811c5d
!python --xformers

Note that we are installing fastapi==0.90. This fixes a bug that prevents the sharing of the Gradio app. Sharing is required to access the interface after it is up and running on the Google server.

We are simply cloning the repo and then checking out the commit that was used in this course. The checkout helps keep everything in the course consistent.

Finally, we are navigating to the repo directory and launching the application. When the application launches, the application will install any required resources.

When this cell finishes, we will see that the application is asking us to download the Stable Diffusion .ckpt file. This is the next step.

No checkpoints found. When searching for checkpoints, looked at:
- file .\stable-diffusion-webui\model.ckpt
- directory .\stable-diffusion-webui\models\Stable-diffusion
Can't run without a checkpoint. Find and place a .ckpt file into any of those locations. The program will exit.

Download Stable Diffusion

To download Stable Diffusion from HuggingFace, we run the command below:

!curl -L --output "/content/stable-diffusion-webui/models/Stable-diffusion/sd-v1-4.ckpt"

This command will download the sd-v1-4.ckpt file to the directory that the Automatic1111 application expects.

This is all that is needed to run the application. However, to avoid doing these downloads every time we run the notebook. We can connect to Google Dive and move the installation over to the Drive.

Google Drive

Running the application from Google Drive will allow us to avoid downloading every time the notebook is relaunched.

Additionally, using Google Drive will make accessing our generated images easier because they will be saved directly to Google Drive. We can mount to Google Drive and check that it is connected by running the following code:

# Mount Google Drive
from google.colab import drive
drive.mount('/content/gdrive', force_remount=True)

# Test Google Drive
google_drive = '/content/gdrive/MyDrive'
%ls $google_drive

Finally, we can move our Automatic1111 application installation to Google Drive, using the following command:

!cp -a /content/stable-diffusion-webui/ /content/gdrive/MyDrive/automatic1111/stable-diffusion-webui

The application will be moved to:


Launching Automatic1111 in Google Colab

Given what we have done so far, we have two options for running the application:

  1. Launch from the Google machine
  2. Launch from the Google Drive

We can launch from the Google machine like so:

%cd /content/stable-diffusion-webui
!python --xformers --share --gradio-auth username:password

We can launch from the Google Drive like so:

%cd /content/gdrive/MyDrive/automatic1111/stable-diffusion-webui
!python --xformers --share --gradio-auth username:password

Launching from Google Drive gives us the advantage that all of our work will be saved after our session is complete. Specifically, the following will be saved in Google Drive:

  • Software downloads
  • App configurations
  • Generated images

Note that we are specifying that we want to --share our interface. This will give us a public link to the web interface.

Therefore, anyone with the link will be able to access the web app that is being hosted by the Google Colab instance. See Gradio: Sharing Your App for more information.

Finally, note that the --gradio-auth parameter allows us to specify a username and password to accessing the app. This restricts the access as the credentials are required. The values in the notebook are place holders.

Change --gradio-auth username:password to something unique. For example:

--gradio-auth chris:4b0b8933c202fdb9ccf88c066a74d560d79b4987

Now, after running the script, we will be provided with a link like so:

Running on public URL:

We click the link, and we are ready to go!

Practice with Flashcards

Challenge your grasp of the concepts by exploring these interactive flashcards.


expand_more chevron_left
deeplizard logo DEEPLIZARD Message notifications

Quiz Results


expand_more chevron_left
For troubleshooting any issues with this Google Colab setup, please go to the DeepLizard Discord server and discuss the issue in the channel for this course. πŸ’₯🦎 DEEPLIZARD COMMUNITY RESOURCES 🦎πŸ’₯ πŸ‘‹ Hey, we're Chris and Mandy, the creators of deeplizard! πŸ‘€ CHECK OUT OUR VLOG: πŸ”— πŸ’ͺ CHECK OUT OUR FITNESS CHANNEL: πŸ”— 🧠 Use code DEEPLIZARD at checkout to receive 15% off your first Neurohacker order: πŸ”— ❀️🦎 Special thanks to the following polymaths of the deeplizard hivemind: Mano Prime πŸ‘€ Follow deeplizard: Our vlog: Fitness: Facebook: Instagram: Twitter: Patreon: YouTube: πŸŽ“ Deep Learning with deeplizard: AI Art for Beginners - Deep Learning Dictionary - Deep Learning Fundamentals - Learn TensorFlow - Learn PyTorch - Natural Language Processing - Reinforcement Learning - Generative Adversarial Networks - Stable Diffusion Masterclass - πŸŽ“ Other Courses: DL Fundamentals Classic - Deep Learning Deployment - Data Science - Trading - πŸ›’ Check out products deeplizard recommends on Amazon: πŸ”— πŸ“• Get a FREE 30-day Audible trial and 2 FREE audio books using deeplizard's link: πŸ”— 🎡 deeplizard uses music by Kevin MacLeod πŸ”— ❀️ Please use the knowledge gained from deeplizard content for good, not evil.


expand_more chevron_left
deeplizard logo DEEPLIZARD Message notifications

Update history for this page

Did you know you that deeplizard content is regularly updated and maintained?

  • Updated
  • Maintained

Spot something that needs to be updated? Don't hesitate to let us know. We'll fix it!

All relevant updates for the content on this page are listed below.