Image Agent with File Upload
Upload a local image file to Gemini and pass it to an agent.
Code
from pathlib import Path
from agno.agent import Agent
from agno.media import File
from agno.models.google import Gemini
from agno.tools.websearch import WebSearchTools
model = Gemini(id="gemini-3.5-flash")
agent = Agent(
model=model,
tools=[WebSearchTools()],
markdown=True,
)
# Please download the image using
# wget https://upload.wikimedia.org/wikipedia/commons/b/bf/Krakow_-_Kosciol_Mariacki.jpg
image_path = Path(__file__).parent.joinpath("Krakow_-_Kosciol_Mariacki.jpg")
if not image_path.is_file():
raise FileNotFoundError(f"Place the sample image at {image_path}")
image_file = model.get_client().files.upload(file=image_path)
print(f"Uploaded image: {image_file}")
agent.print_response(
"Tell me about this image and give me the latest news about it.",
files=[File(external=image_file)],
stream=True,
)Usage
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateDownload the image
Run this in the directory where you will save image_input_file_upload.py:
wget https://upload.wikimedia.org/wikipedia/commons/b/bf/Krakow_-_Kosciol_Mariacki.jpgSet your API key
export GOOGLE_API_KEY=xxxInstall dependencies
uv pip install -U google-genai ddgs agnoRun Agent
Save the code above as image_input_file_upload.py, then run:
python image_input_file_upload.py