Image To Text

Image to Text Example.

1"""
2Image To Text
3=============================
4
5Image to Text Example.
6"""
7
8from pathlib import Path
9
10from kern.agent import Agent
11from kern.media import Image
12from kern.models.openai import OpenAIResponses
13
14# ---------------------------------------------------------------------------
15# Create Agent
16# ---------------------------------------------------------------------------
17agent = Agent(
18 model=OpenAIResponses(id="gpt-5.2"),
19 markdown=True,
20)
21
22image_path = Path(__file__).parent.joinpath("sample.jpg")
23
24# ---------------------------------------------------------------------------
25# Run Agent
26# ---------------------------------------------------------------------------
27if __name__ == "__main__":
28 agent.print_response(
29 "Write a 3 sentence fiction story about the image",
30 images=[Image(filepath=image_path)],
31 )

Run the Example

1# Clone and setup repo
2git clone https://github.com/kern-ai/kern.git
3cd kern/cookbook/02_agents/12_multimodal
4
5# Create and activate virtual environment
6./scripts/demo_setup.sh
7source .venvs/demo/bin/activate
8
9python image_to_text.py