Article

Table of Contents
Theme:
Was this article helpful?
Try Vultr Today with

$50 Free on Us!

Want to contribute?

You could earn up to $600 by adding new articles.

Create a Stable Diffusion Web UI with a Vultr Cloud GPU

Author: Kenn Carlo Gutierrez

Last Updated: Fri, Nov 4, 2022
Machine Learning Vultr Cloud GPU

Introduction

Stable Diffusion is a deep learning model that can generate detailed images based on input text descriptions. It can also be used to enhance an existing image or generate a new one based on another, guided by a text description prompt. This guide explains how to create a Stable Diffusion web UI on a Vultr Cloud GPU running on Ubuntu 22.04 using this Stable Diffusion web UI repository on GitHub.

Prerequisites

Security Considerations

This guide creates a web UI for Stable Diffusion, but does not provide any protection from unwanted users or attacks. We strongly recommend that you protect your installation with a proxy or firewall, like these options:

Create a Stable Diffusion Web UI

  1. Install Git Large File Storage (LFS) to clone the Stable Diffusion model.

    $ sudo apt install git-lfs
    
  2. Initialize Git Large File Storage (LFS).

    $ git lfs install
    
  3. Clone the Stable Diffusion repository. Enter your Hugging Face account credentials twice when prompted.

    $ git clone https://huggingface.co/CompVis/stable-diffusion-v-1-4-original
    

    You only need the weights or the sd-v1-4.ckpt checkpoint file from this repository.

  4. Wait for the cloning to finish.

  5. Clone the Stable Diffusion Web UI Repository.

    $ git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
    
  6. Copy the sd-v1-4.ckpt checkpoint file from the Stable Diffusion directory to the stable-diffusion-webui/models/Stable-diffusion/ Web UI directory and rename it as model.ckpt

    $ cp ~/stable-diffusion-v-1-4-original/sd-v1-4.ckpt ~/stable-diffusion-webui/models/Stable-diffusion/model.ckpt
    
  7. Remove the Stable Diffusion folder you have cloned because you only need the sd-v1-4.ckpt file.

    $ rm -rf ~/stable-diffusion-v-1-4-original
    
  8. Install the FastAPI framework using pip.

    $ pip3 install fastapi
    
  9. The Stable Diffusion Web UI runs on port 7860 by default, so you must enable port 7860 on your firewall.

    $ sudo ufw allow 7860
    

Run the Stable Diffusion Web UI with Tmux

When you run your Stable Diffusion Web UI on a normal SSH session, the Web UI's process closes when you exit the SSH session. To continuously run your Web UI even when you leave the SSH session, use tmux, a terminal multiplexer.

  1. To create a Tmux session, run:

    $ tmux new -s StableDiffusion
    

    You may change StableDiffusion with any session name you prefer. Please see How to Install and Use Tmux for more information about Tmux.

  2. Change the directory to stable-diffusion-webui.

    $ cd ~/stable-diffusion-webui
    
  3. Launch the Stable Diffusion Web UI by running launch.py using python.

    $ python3 launch.py --listen
    

    The --listen argument makes your Web UI listen to network connections, not just on localhost. Please see Command Line Arguments and Settings for more information.

  4. Wait until your server launches.

  5. Detach from the Tmux session by pressing CTRL + B then D.

Test the Stable Diffusion Web UI

  1. In your browser, navigate to port 7860 at your server's IP address. For example, http://192.0.1.2:7860.

  2. Under the Stable Diffusion checkpoint dropdown menu, select model.ckpt.

  3. Select the txt2img tab.

  4. Enter any text description in the Prompt text field.

  5. Increase or decrease the sample steps to generate better or poorer images. Higher sample steps produce better images but take more time to generate one. Lower sample steps generate much faster but produce poorer images.

  6. To learn more about the different sampling methods, seed resize, and other features, please see the Stable Diffusion Web UI Features Documentation.

  7. You may increase or decrease the image's size by adjusting the width and the height.

  8. Click Generate to start producing the image.

  9. Please see the image below for an example.

Example - Stable Diffusion Web UI

You have successfully created a Stable Diffusion Web UI on a Vultr Cloud GPU.

More Information

To learn more about Stable Diffusion, please see these resources:

Want to contribute?

You could earn up to $600 by adding new articles.