Skip to main content
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 on Cerebrium is similar to a virtual machine or Google Colab. Install the Cerebrium package and log in before proceeding. See the installation docs for details. First, create your project:
Configure your compute and environment settings in cerebrium.toml:
Create a main.py file. This implementation fits in a single file. Start by defining the request object:
The code uses Pydantic for data validation. The prompt and url parameters are required; all others are optional. Missing required parameters trigger an automatic error message.

Instantiate model

The SDXL model loads outside the predict function since it only needs to load once at startup. The model downloads during initial deployment and is automatically cached in persistent storage for subsequent use.

Predict Function

The predict function takes parameters from the request, passes them to the SDXL model, and returns base64-encoded images for direct JSON-serializable responses.

Deploy

Deploy the model using this command:
After deployment, make this request:
The endpoint returns results in this format:
Example output: SDXL