Multimodal Evaluation: Images, Audio, and PDF

Run Future AGI's built-in image, audio, and PDF eval metrics from the SDK or the dashboard.

📝
TL;DR

Score image captions, detect AI-generated images, evaluate audio quality and TTS accuracy, and verify OCR output against source PDFs using built-in multimodal eval metrics.

Open in ColabGitHub
TimeDifficultyPackage
10 minIntermediateagent-learning-kit
Prerequisites
  • Future AGI account → app.futureagi.com
  • API keys: FI_API_KEY and FI_SECRET_KEY (see Get your API keys)
  • Python 3.11 or 3.12
  • FFmpeg with the flite audio filter to synthesize the short sample clip

Install

python3 -m venv .venv
source .venv/bin/activate
python -m pip install agent-learning-kit==0.3.7 Pillow==11.3.0
export FI_API_KEY="your-api-key"
export FI_SECRET_KEY="your-secret-key"

Tutorial

Set up the Evaluator

Start in an empty directory and run the Python blocks in order in one session. Each call to evaluate() uses a hosted evaluator and can consume credits. Keep the evaluation IDs if you want to retrieve the results later.

import base64
import io
import json
import subprocess
from pathlib import Path

from PIL import Image, ImageDraw
from fi.evals import Evaluator

evaluator = Evaluator()
judgments = []

def media_uri(mime, content):
    return f"data:{mime};base64," + base64.b64encode(content).decode("ascii")

def score(template, inputs, model):
    batch = evaluator.evaluate(eval_templates=template, inputs=inputs, model_name=model)
    row = batch.eval_results[0]
    if row is None or row.output is None or not row.eval_id:
        raise RuntimeError(row.reason if row else "No judgment returned")
    judgments.append({"name": template, "eval_id": row.eval_id, "verdict": row.output})
    print(f"{template}: {row.output}\nReason: {row.reason}")

Detect caption hallucination

Create a sample product icon: a red triangle on a white background. Score a caption that matches the icon.

Note

Turing models run on Future AGI’s managed service. On Future AGI Cloud, each Turing evaluation uses AI credits from your organization’s plan. A self-hosted deployment needs a license that includes the turing_models feature; its Turing calls use that license’s managed AI credits and are not available in an air-gapped install. On a self-hosted install, set FI_BASE_URL to your API URL first. Without it, your keys and inputs go to Future AGI Cloud.

icon = Image.new("RGB", (192, 192), "white")
ImageDraw.Draw(icon).polygon([(96, 20), (26, 162), (166, 162)], fill="red")
buffer = io.BytesIO()
icon.save(buffer, format="PNG")
image = media_uri("image/png", buffer.getvalue())
score("caption_hallucination", {"image": image, "caption": "A red triangle on a white background."}, "turing_small")

Keep the image fixed and change only the caption:

score("caption_hallucination", {"image": image, "caption": "A blue bicycle leaning against a tree."}, "turing_small")

Look for Passed on the matching caption and Failed on the invented bicycle. Read the reason to see which details the judge used.

Detect synthetic images

Use the same icon to estimate whether the image was synthetically produced. The score expresses the judge’s assessment, not proof of how an image was made.

score("synthetic_image_evaluator", {"image": image}, "turing_small")

Evaluate audio quality

Generate a short WAV file with synthesized speech, then score its clarity, noise, and naturalness. The audio-quality template uses a normalized score, not a listener panel’s 1-to-5 MOS rating.

text = "Unused gear can be returned within thirty days."
subprocess.run([
    "ffmpeg", "-v", "error", "-f", "lavfi", "-i", f"flite=text={text}:voice=slt",
    "-ac", "1", "-ar", "16000", "returns.wav",
], check=True)
audio = media_uri("audio/wav", Path("returns.wav").read_bytes())
score("audio_quality", {"input_audio": audio}, "turing_large")

Evaluate text-to-speech accuracy

Does the clip say what the return policy actually says? Pass both the audio and its original script to the TTS evaluator. Unlike the previous audio-only check, this one also considers pronunciation and delivery against the text.

score("TTS_accuracy", {"text": text, "generated_audio": audio}, "turing_large")

Evaluate OCR output against a PDF

Build a one-page sample packing slip for Ridgeline Outfitters. The evaluator reads the PDF’s text layer, so write the slip as PDF text rather than as a scanned image; an image-only PDF is judged as a blank page. Supply the PDF and the fields you extracted, not just the extracted text.

lines = ["Ridgeline Outfitters", "Packing slip: RO-1042", "Item: Trail mug", "Quantity: 2"]
text = "BT /F1 24 Tf 50 740 Td 30 TL " + " ".join(f"({line}) '" for line in lines) + " ET"
objects = [
    "<< /Type /Catalog /Pages 2 0 R >>",
    "<< /Type /Pages /Kids [3 0 R] /Count 1 >>",
    "<< /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792] /Contents 4 0 R "
    "/Resources << /Font << /F1 5 0 R >> >> >>",
    f"<< /Length {len(text)} >>\nstream\n{text}\nendstream",
    "<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>",
]
pdf, offsets = b"%PDF-1.4\n", []
for number, body in enumerate(objects, 1):
    offsets.append(len(pdf))
    pdf += f"{number} 0 obj\n{body}\nendobj\n".encode()
xref = len(pdf)
pdf += f"xref\n0 {len(objects) + 1}\n0000000000 65535 f \n".encode()
pdf += "".join(f"{offset:010d} 00000 n \n" for offset in offsets).encode()
pdf += f"trailer\n<< /Size {len(objects) + 1} /Root 1 0 R >>\nstartxref\n{xref}\n%%EOF\n".encode()
score("ocr_evaluation", {
    "input_pdf": media_uri("application/pdf", pdf),
    "json_content": json.dumps({"packing_slip": "RO-1042", "item": "Trail mug", "quantity": 2}),
}, "turing_large")
Path("multimodal-results.json").write_text(json.dumps(judgments, indent=2), encoding="utf-8")

The reason should explain which JSON values are supported by the source. multimodal-results.json records each template, evaluation ID, and verdict from this session.

Run multimodal evals from the dashboard

You can also run these evals directly from the Future AGI platform without writing any code.

  1. Go to Datasets and create or open a dataset
  2. Add columns for your multimodal inputs, for example an image column with image URLs, or an audio column with audio URLs
  3. Click Add Evaluation and select a multimodal eval, for example caption_hallucination or audio_quality
  4. Map the eval’s required keys to your dataset columns, for example image to your image column and caption to your caption column
  5. Choose a Turing model and click Run
  6. View scores alongside each row in the dataset

This is the same approach shown in the Dataset SDK cookbook, but with multimodal columns instead of text-only.

Troubleshooting

SymptomCauseFix
Evaluator() raises a missing-credentials errorFI_API_KEY or FI_SECRET_KEY isn’t exported before the script runsExport both keys, or pass fi_api_key/fi_secret_key directly to Evaluator()
audio_quality or ocr_evaluation returns an unsupported-model errorCalled with model_name="turing_small" instead of turing_largeUse model_name="turing_large" for these evals
caption_hallucination or synthetic_image_evaluator comes back empty or errorsThe image URL isn’t publicly reachable, for example a private bucket or an expired signed URLUse a publicly accessible URL, or pass the image as base64
ocr_evaluation scores low even on a correct extractionjson_content isn’t valid JSON, for example a trailing comma or an unescaped quoteValidate the string with json.loads() before passing it in
TTS_accuracy or audio_quality times out on a long clipThe input audio runs several minutes and the evaluation model processes it in fullTrim the clip to the relevant segment before scoring
result.eval_results[0] is NoneThat row failed to evaluate, usually a bad input URL or an unsupported file typeCheck the entry for None before reading .output or .reason, and re-check the input for that row

Next up

Ready to score plain text next? See Running Your First Eval for text evals and LLM-as-Judge.

Was this page helpful?

Questions & Discussion