Generate Images using SDXL
Generate high quality images using SDXL with refiner
This example is only compatible with CLI v1.20 and later. Should you be making
use of an older version of the CLI, please run pip install --upgrade cerebrium
to upgrade it to the latest version.
This tutorial shows you how to generate high-quality images using the SDXL refiner model from Stability AI, available on Hugging Face.
To see the final implementation, you can view it here
Basic Setup
Developing models with Cerebrium is similar to developing on a virtual machine or Google Colab, making conversion straightforward. Make sure you have the Cerebrium package installed and are logged in. If not, check our docs here.
First, create your project:
Configure your compute and environment settings in cerebrium.toml
:
Create a main.py
file for our Python code. This simple implementation can be done in a single file. First, let’s define our request object:
We import the required Python libraries and use Pydantic for data validation. The prompt
and url
parameters are required, while all others are optional. Missing required parameters will trigger an automatic error message.
Instantiate model
We load the SDXL model outside the predict
function since it only needs to be loaded once at startup. While the model downloads during initial deployment, it’s automatically cached in persistent storage for subsequent use.
Predict Function
The predict
function takes parameters from the request and passes them to the SDXL model to generate images. We convert images to base64 for direct JSON-serializable responses instead of writing to S3.
Deploy
Deploy the model using this command:
After deployment, make this request:
The endpoint returns results in this format:
Example output: