Create a picture using stable diffusion & upload it using Spheron SDK

Rohan SharmaRohan Sharma
4 min read

Table of Content

1. Getting started with stable diffusion

2. Uploading the file to Spheron SDK

Getting started with Stable Diffusion

Stable Diffusion is a deep learning, text-to-image model released in 2022. It is primarily used to generate detailed images conditioned on text descriptions, though it can also be applied to other tasks such as inpainting, outpainting, and generating image-to-image translations guided by a text prompt.

Download and install Stable Diffusion

Install Stable Diffusion on your computer instead of using websites. Setup is challenging and requires precise steps, but once done, it can be run whenever and how often.

To start, ensure your PC meets minimum requirements for Windows 10 or 11, and a discrete NVIDIA video card with 4GB or more VRAM. Use the DirectX Diagnostic Tool to check the card's name, model, and VRAM amount. Press Win key+R to trigger the Run box, type dxdiag in the Open field, and click the Display tab to view the card's name and VRAM.

Now follow the following steps:

  1. Install Python

    Browse to the Python 3.10.6 website. Scroll down to the Files section and click the link for the Windows installer (64-bit) (assuming you're running 64-bit Windows). Run the downloaded file to install Python.

  2. Install Git

    Browse to the Download page for Git for Windows. Click the link for 64-bit Git for Windows Setup. Install the downloaded file, accepting all the default options.

  3. Download the Stable Diffusion Project file

    Browse to the GitHub page for the Stable Diffusion project file. Click the green Code button in the upper right and select Download ZIP. Extract the downloaded ZIP file. Doing so creates a folder named stable-diffusion-webui-master. Copy this folder with all the extracted files to a simple location, such as the root of your C: drive.

  4. Download and setup the checkpoint file

    Browse to the Hugging Face webpage for the Stable Diffusion checkpoint file. Click the download link to save the 768-v-ema.ckpt file. This is a huge file, so be patient while it downloads. After the file has been downloaded, navigate to the following location: C:\stable-diffusion-webui-master\models\Stable-diffusion (assuming you copied this folder to the root of your C: drive). Inside this folder is a file named Put Stable Diffusion checkpoints here.txt. Copy the 768-v-ema.ckpt file into this folder.

  5. Download the config yaml file

    Browse to the page for the config yaml file. The file will appear as straight text. Right-click anywhere on the page and select Save as. Navigate to the C:\stable-diffusion-webui-master\models\Stable-diffusion folder and save the yaml file in this location. Change the name of the file to 768-v-ema but keep the yaml extension, so it should be named 768-v-ema.yaml.

  6. Run the webui-user.bat file

    Move to the stable-diffusion-webui-master folder and run the webui-user.bat file. After a couple of minutes, the window should display a line that reads: Running on local URL, followed by a URL with the IP address of your local machine and a port number. Copy and paste that entire URL with the port number into your favorite browser to display the Stable Diffusion application. However, keep the command window open.

  7. Generate an image

    Now you can finally generate an image. In the Stable Diffusion application, type a description for the image you want at the prompt. Enter any text you wish to exclude in the Negative prompt. If you want, you can change the parameters for Sampling method, width, height, and the rest. Set values for Batch count and Batch size if you need to change the defaults. When ready, click the Generate button. The application displays the images based on the count you requested.

Generate and view the images.  Screenshot by Lance Whitney/ZDNET

Reference: https://www.zdnet.com/article/how-to-use-stable-diffusion-ai-to-create-amazing-images/

Uploading the file to Spheron SDK

What is Spheron SDK?

The Spheron SDK simplifies the process of uploading images to various platforms and applications. It provides a user-friendly interface and robust functionality for seamless integration.

Integrating the Spheron SDK into the generated image

# Importing the Spheron SDK library
import spheron

# Connecting to the Spheron SDK
spheron.connect()

# Uploading the processed image
image_path = "processed_image.jpg"
spheron.upload(image_path)

# Disconnecting from the Spheron SDK
spheron.disconnect()
3
Subscribe to my newsletter

Read articles from Rohan Sharma directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Rohan Sharma
Rohan Sharma

I am a developer, writer and open-source lover