Examples
Image to Structured Output
Hackathon Resources
- Introduction
- Setup
- Examples
- Simple Text Agent
- Agent with Tools
- Agent with Knowledge
- Agent with Structured Outputs
- Research Agent
- YouTube Agent
- Image Input + Tools
- Image Generation using DALL-E
- Image to Structured Output
- Image Generate Audio
- Image Input + Output
- Image Transcription
- Image search using Giphy
- Audio Input
- Audio Input Output
- Audio Sentiment
- Audio Transcript
- Audio Multi Turn
- Audio Generate Podcast
- Video Input
- Video Generation with Models Lab
- Video Generation with Replicate
- Video Captions
- Video to Shorts
- Models
- Pre-built Replit Template
- 🏆 Prizes
Examples
Image to Structured Output
This agent can extract structured data from images.
image_to_structured_output.py
from typing import List, Optional
from agno.agent import Agent
from agno.media import Image
from agno.models.openai import OpenAIChat
from pydantic import BaseModel
class Item(BaseModel):
item_name: str
price: float
class Invoice(BaseModel):
restaurant: Optional[str] = None
address: Optional[str] = None
bill_number: Optional[str] = None
items: List[Item]
total: Optional[float] = None
agent = Agent(
model=OpenAIChat(id="gpt-4o"),
response_model=Invoice,
structured_outputs=True,
)
agent.print_response(
"Extract the items and prices from the invoice",
images=[Image(url="https://upload.wikimedia.org/wikipedia/commons/c/cf/Receipt_California_restaurant_2006.jpg")],
)
Usage
1
Install libraries
pip install -U agno openai
2
Export API keys
export OPENAI_API_KEY=***
3
Run the agent
python image_to_structured_output.py
On this page