Skip to main content
This tutorial transcribes an hour-long audio file using Distill Whisper — an optimized version of Whisper-large-v2 that’s 60% faster while maintaining accuracy within 1% of the original. The endpoint accepts either a base64-encoded string of the audio file or a URL to download the audio file. 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. Install the Cerebrium package and log in. See the installation docs for details. Create the project:
Add the following packages to the [cerebrium.dependencies.pip] section of your cerebrium.toml file:
Create a util.py file for utility functions — downloading a file from a URL or converting a base64 string to a file:
With the utility functions complete, update main.py with the main application code. The endpoint accepts either a base64-encoded string or a public URL of the audio file, passes it to the model, and returns the output. Define the request object:
Pydantic handles data validation. While audio and file_url are optional parameters, at least one must be provided. The webhook_endpoint parameter, automatically included by Cerebrium in every request, is useful for long-running requests. Note: Cerebrium has a 3-minute timeout for each inference request. For long audio files (2+ hours) that take several minutes to process, use a webhook_endpoint — a URL where Cerebrium sends a POST request with the function’s results.

Setup Model and inference

Import the required packages and load the Whisper model. The model downloads during initial deployment and is automatically cached in persistent storage for subsequent use. Loading the model outside the predict function ensures this code only runs on cold start (startup). For warm containers, only the predict function executes for inference.
The predict function, which runs only on inference requests, creates an audio file from either the download URL or base64 string, transcribes it, and returns the output.

Deploy

Configure your compute and environment settings in cerebrium.toml:
Deploy the app using this command:
After deployment, make this request:
The response returns immediately with a 202 status code and a run_id — a unique identifier to correlate the result with the initial workload. The endpoint returns results in this format: