Create Stunning Images with AI on Any PC! Learn How on Amazon SageMaker Studio Lab

Find AI Tools
No difficulty
No complicated process
Find ai tools

Create Stunning Images with AI on Any PC! Learn How on Amazon SageMaker Studio Lab

Table of Contents

  1. Introduction
  2. Setting up the Environment
  3. Overview of the Generation Environment
  4. Tools Required for the Environment Setup
  5. Setting up SageMaker Studio Lab
  6. Creating an Account on Hugging Face
  7. Obtaining the Hugging Face Access Token
  8. Creating an Account on ngrok
  9. Obtaining the ngrok Access Token
  10. Setting up the Environment in SageMaker Studio Lab
  11. Creating a Virtual Environment with Python 3.10.6
  12. Installing ipykernel
  13. Cloning the Stable Diffusion Web UI Repository
  14. Setting up the Hugging Face Access Token
  15. Downloading the Model Files
  16. Installing Required Packages for the WebUI
  17. Launching the WebUI
  18. Troubleshooting the WebUI Startup Errors
  19. Generating an Image
  20. Conclusion

Introduction

In this tutorial, I will guide You through the process of setting up Stable Diffusion, an image generation AI, for free. While running Stable Diffusion on a local environment requires a high-spec PC with a GPU, I will Show you how to Create a generation environment using free tools. This tutorial is aimed at those who prefer to set up the environment on their own rather than using cloud services or pre-built websites. We will cover the necessary tools, account creation, environment setup, and troubleshooting along the way. Let's get started!

Setting up the Environment

To begin, let's first understand the overall structure of the generation environment using the four tools Mentioned in this tutorial: SageMaker Studio Lab, Stable Diffusion Web UI, Hugging Face, and ngrok. We will be using SageMaker Studio Lab, a development environment provided by Amazon for machine learning, to create a GPU execution environment on the cloud. Then, we will copy the Stable Diffusion Web UI repository into this execution environment. Next, we'll download the image generation model from Hugging Face and place it within the Web UI repository. Finally, we'll launch the Web UI using ngrok, which provides external access to web servers running on your PC.

Overview of the Generation Environment

Before we dive into the setup process, let me provide you with an overview of the generation environment. This will help you better understand the subsequent explanations. We will start by creating an account for SageMaker Studio Lab, where we will initiate the GPU execution environment. Then, we'll create an account on Hugging Face to access their models and datasets. We'll also create an account on ngrok to facilitate external access to the Web UI. Once the accounts are set up, we will proceed to create a virtual environment with the recommended Python version. After that, we'll clone the Stable Diffusion Web UI repository and set up the Hugging Face access token. Once the setup is complete, we'll be ready to launch the Web UI and start generating images.

Tools Required for the Environment Setup

To set up the environment, we will need four tools:

  1. SageMaker Studio Lab: A development environment provided by Amazon for machine learning, serving as an alternative to Google Colab. It allows us to create a GPU execution environment on the cloud.
  2. Stable Diffusion Web UI: A tool released by AUTOMATIC1111 that provides a web browser interface for working with Stable Diffusion. It is the de facto standard tool for using Stable Diffusion with a Web UI.
  3. Hugging Face: A site similar to GitHub, designed for sharing files used in AI and machine learning. It offers numerous image generation AI models and allows us to publish learning models and datasets.
  4. ngrok: A service that facilitates external access to web servers running on your PC. We will use it to launch the Web UI securely.

Now that we know the tools required, let's proceed with setting up each of them.

Setting up SageMaker Studio Lab

To set up the environment, we will first create an account for SageMaker Studio Lab. Begin by visiting the official Website and clicking on the 'Sign Up' button. You will be prompted to enter your email address and name. For fields other than the email address, you can input random information. Once you've completed the input, click 'Sign Up'. You will receive a confirmation email at the address you provided. Click the button in the email to complete the application process. Please note that the account review process may take a few days. Once you receive the completion email, choose a username and password to finalize your account creation.

Creating an Account on Hugging Face

Next, we will create an account on Hugging Face. Visit the Hugging Face website and click on the 'Sign Up' button. Enter your email address and password to proceed. You will also need to provide a username and agree to the terms of use. Once you've entered the required information, click 'Sign Up'. A confirmation email will be sent to the provided address. Click the link in the email to confirm your account creation.

Obtaining the Hugging Face Access Token

To access the models and datasets on Hugging Face, we need to obtain an access token. Once you've signed in to your Hugging Face account, open the Settings page from your profile icon. Navigate to the Access Tokens tab and click 'New Token'. Give the token a suitable name and leave the permissions as they are. Copy the access token and store it in a safe place for future reference.

Creating an Account on ngrok

To facilitate external access to the Web UI, we will create an account on ngrok. You can either register using your email address or use your Google account for a simpler process. Visit the ngrok website and choose the registration method you prefer. Once you've registered, you will be prompted to set up two-factor authentication, which is highly recommended for added security. However, for now, we'll skip this step. After signing in, navigate to the Your Authtoken tab to obtain your ngrok access token. Copy the token and keep it easily accessible for future use.

Setting up the Environment in SageMaker Studio Lab

In SageMaker Studio Lab, you'll see "My project" displayed upon signing in. Click on it to access the project page. Here, you'll find the status of your execution environment and the remaining time for your available Sessions. Keep in mind that the remaining time resets every 24 hours but won't stop unless you manually end the session. Change the runtime Type to 'Python 3 (Data Science)' and click 'Update'. Please note that phone number verification will be required the first time you change the runtime type. After solving the simple Puzzle, wait for the execution environment to launch. It might take around 30 seconds for it to boot up.

Now that we have set up the environment and created the necessary accounts, let's proceed with the remaining steps to complete the setup process. In the next section, we will create a virtual environment and install the required packages for running Stable Diffusion."""

Installation Process

In this step, we will prepare a virtual environment with the recommended Python version (3.10.6) and install the necessary packages for running Stable Diffusion. To start, open a new terminal from the 'Launcher' tab in SageMaker Studio Lab. Check the default installed version of Python by entering the command python --version. If the version is different from 3.10.6, create a new virtual environment with the specific version by using the command conda create -n myenv python=3.10.6. Replace 'myenv' with the desired name for your virtual environment. Once the installation starts, wait for it to complete.

Now, navigate to the newly created virtual environment by using the command conda activate myenv (replace 'myenv' with the name of your virtual environment). To verify that Python 3.10.6 is successfully installed, check the version again using the command python --version. You should see Python 3.10.6 as the output. Next, install ipykernel by running the command pip install ipykernel. This will enable you to select the virtual environment from SageMaker Studio Lab's Launcher.

After installing ipykernel, refresh the page in SageMaker Studio Lab's Launcher. You should now see the newly created virtual environment listed. Select it and proceed to the next step.

Cloning the Stable Diffusion Web UI Repository

Now that we have the virtual environment set up, let's clone the Stable Diffusion Web UI repository and navigate to its directory. Open a new file with an appropriate name and check the execution environment by selecting a cell and pressing the 'Run' button. The GPU available in the execution environment will be displayed. Clone the repository by running the following command: git clone https://github.com/AUTOMATIC1111/stable-filtering-webui.git. Once the repository is cloned, a new folder will be created in the Current directory.

Setting up the Hugging Face Access Token

To set up the Hugging Face access token, open the file named src/config.py in the cloned repository. Paste the access token you obtained earlier into the appropriate section of the file. Save the changes and execute the cell to set up the access token.

Downloading the Model Files

Now, let's download the model files from Hugging Face. Open the Hugging Face website and explore the available models. Select the model you want to use for image generation and click on it to view more details. On the model's page, you will find sample Prompts and other settings. Download the model files by clicking on the download button. Choose the file format you prefer (.ckpt or .safetensors) and specify the destination folder as /models/Stable-Diffusion. The download might take some time, especially for larger models.

Once the download is complete, the model files will be placed in the specified folder.

Installing Required Packages for the WebUI

With the model files downloaded, let's install the required packages for launching the WebUI. Open a new terminal and navigate to the cloned repository's directory (stable-filtering-webui). Run the command pip install -r requirements.txt to install the necessary packages. The installation process might take a few minutes, so please be patient. Once the installation is complete, you should see 'Successfully installed' followed by a list of packages.

Launching the WebUI

Now, it's time to launch the WebUI. To start the WebUI, execute the cell responsible for launching it. Set the ngrok access token you obtained earlier as an argument. For added security, you can also set the gradio password as an argument. Once everything is set, execute the cell.

If everything goes smoothly, you will see two URLs displayed. To access the WebUI, click on the upper URL, which is the ngrok URL. This will open the WebUI in your browser. Use the ID and password you set as arguments to log in. Remember to keep your ID and password confidential. Congratulations! The WebUI has started successfully.

Troubleshooting the WebUI Startup Errors

During the startup process, you might encounter errors. The WebUI undergoes frequent updates, and errors are common. Let's troubleshoot the errors we have encountered in this tutorial.

  1. If you encounter a missing module error, open the files that import the module (src/webui.py and src/photorealistic_filtering.py) and replace 'distributed' with 'rank_zero'.

  2. If you encounter an AttributeError when loading the model, it might be due to the version of the 'pydantic' module. Reinstall the module with a specified version using the command pip install pydantic==1.9.0.

  3. If the WebUI still fails to start, consider reviewing the error messages and searching for solutions in the Stable Diffusion Web UI repository's issue section on GitHub.

Remember to keep track of any modifications you make and share your findings with the community to help others who may encounter similar issues.

Generating an Image

Now that the WebUI is up and running, let's try generating an image. Use a sample prompt provided on the downloaded model's page or come up with your own. Set the prompt and adjust the image size and sampler settings Based on your preferences. Once you're ready, click the "Generate" button to start the image generation process.

The progress of the generation will be displayed in the notebook. Once it reaches 100%, the generation is complete. On the WebUI side, the generated image will be displayed. Enjoy exploring the capabilities of image generation AI!

Conclusion

In this tutorial, we have covered the process of setting up Stable Diffusion, an image generation AI, using free tools. We started by creating accounts for SageMaker Studio Lab, Hugging Face, and ngrok. Then, we set up the environment in SageMaker Studio Lab, including creating a virtual environment with the recommended Python version, cloning the Stable Diffusion Web UI repository, and downloading the model files. We also installed the required packages for launching the WebUI and troubleshooted common startup errors. Finally, we generated an image using the WebUI and enjoyed the capabilities of image generation AI.

It's important to note that while this tutorial provides a comprehensive guide, errors and challenges might arise due to updates or changes in the environment. If you encounter any mistakes, have questions, or want to share your insights, please feel free to leave a comment. Your feedback and contributions are highly appreciated.

Thank you for following along with this tutorial. I hope it has been informative and inspiring. Have fun exploring the world of image generation AI!

Most people like

Are you spending too much time looking for ai tools?
App rating
4.9
AI Tools
100k+
Trusted Users
5000+
WHY YOU SHOULD CHOOSE TOOLIFY

TOOLIFY is the best ai tool source.

Browse More Content