Use files with models
Learn how to pass files to models and receive files from them
Models that accept files as input, or return files as output, use either of these forms:
| Form | Best for |
|---|---|
| HTTP URL | Large files, and files that are already online |
| Base64 data URL | Small files you want to send inline with the request |
A base64 data URL is about a third larger than the file, must be held in memory in full, and has to be sent inline with the request, so prefer an HTTP URL in most cases.
Here is an example to run systran/faster-whisper-large-v3 with a local audio file. While you can upload the file yourself and pass its URL when creating a prediction, WriftAI's official clients do both automatically:
from pathlib import Path
from wriftai import Client, File
# Instantiate the WriftAI client
wriftai = Client()
# The file is uploaded automatically before the prediction is created
prediction = wriftai.predictions.create(
model="systran/faster-whisper-large-v3",
input={"audio": File(Path("interview.mp3"))},
)import { openAsBlob } from 'node:fs';
import { WriftAI, FileData } from 'wriftai';
// Instantiate the WriftAI client
const wriftai = new WriftAI();
// The file is uploaded automatically before the prediction is created
const prediction = await wriftai.predictions.create({
model: 'systran/faster-whisper-large-v3',
input: {
audio: new FileData(await openAsBlob('./interview.mp3'), 'audio/mpeg'),
},
});import (
"context"
"log"
"os"
"github.com/wriftai/wriftai-go"
)
func main() {
// Instantiate the WriftAI client
client := wriftai.NewClient()
file, err := os.Open("interview.mp3")
if err != nil {
log.Fatal(err)
}
defer file.Close()
// The file is uploaded automatically before the prediction is created
_, err = client.Predictions.Create(
context.TODO(),
wriftai.CreatePredictionParams{
Model: "systran/faster-whisper-large-v3",
Input: wriftai.PredictionInput{
"audio": wriftai.NewFile(file, ""),
},
},
)
if err != nil {
log.Fatal(err)
}
}# The file is uploaded automatically before the prediction is created
wriftai predictions create \
--model systran/faster-whisper-large-v3 \
--input audio@interview.mp3# Pass an HTTP URL, no upload needed
curl "https://api.wrift.ai/v1/predictions" \
-H "Authorization: Bearer $WRIFTAI_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"model": "systran/faster-whisper-large-v3",
"input": {
"audio": "https://example.com/interview.mp3"
}
}'More file input options
Clients support more ways to pass files, such as bytes, streams, and nested inputs. Refer to the reference of each client for all options.
Files in the playground
File inputs are also supported in the UI. When a model takes a file, its playground lets you select a file to upload and run, with no code required.