Skip to main content
This example demonstrates an AI Avatar app, built using DreamBooth and Stable Diffusion v1.5.

Overview

This app has two APIs. The first API is used to start a fine-tuning job on a batch of image URLs. The second API is used to generate an image using the fine-tuned model.

Training

This endpoint will take a list of input images as URLs, and fine-tune Stable Diffusion on those images. It also takes a user ID, so that you can reference the specific fine-tuned model later on when you generate customized images.
app-training.py
We’ll deploy the training API by running:
Once the app spins up, you can find the API URL in the web dashboard and send a request to start a training job.

Starting a fine-tuning task

After deploying the app, you can kick-off a fine-tuning job by calling the API with a JSON payload like this:
We’ll pass in a bunch of images of cat toys:
Here’s what the complete cURL request will look like:
This code runs asynchronously, so a task ID is returned from the request:
We can view the status of the training job by querying the task API:
This returns the task status. If the task is completed, we can call the inference API to use our newly fine-tuned model.

Inference

Now that we’ve setup our fine-tuning API, we’ll move onto the code that runs inference with the fine-tuned model:
app-inference.py

Deployment

You can deploy this by running beam deploy app-inference.py. Once it’s deployed, you can find the web URL in the dashboard.
Here’s what a request will look like:
This function also runs asynchronously, so a task ID is returned:

Querying task status

We can view the status of the inference request by querying the task API:
If the request is completed, you’ll see an image-output field in the response.

Retrieving image outputs

Enter this the image-output URL in the browser. It will download a zip file with the image generated from the model. And there you go — a cat toy riding the subway: