Ollama Demo Gemma
Stream a short story about a local image from Gemma 3 12B running on Ollama.
"""
Ollama Demo Gemma
=================
Cookbook example for `ollama/chat/demo_gemma.py`.
"""
from pathlib import Path
from agno.agent import Agent
from agno.media import Image
from agno.models.ollama import Ollama
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
agent = Agent(model=Ollama(id="gemma3:12b"), markdown=True)
image_path = Path(__file__).parent.joinpath("super-agents.png")
agent.print_response(
"Write a 3 sentence fiction story about the image",
images=[Image(filepath=image_path)],
stream=True,
)
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
passRun the Example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U agno ollamaSelect the local Ollama server
In the shell used for the pull commands and Python example, clear a previous cloud key and point native clients and embeddings at your local server:
unset OLLAMA_API_KEY
export OLLAMA_HOST="http://localhost:11434"Without this reset, OLLAMA_API_KEY makes Agno's default Ollama model route to https://ollama.com even when OLLAMA_HOST points locally. Keep a local Ollama server running for the following steps.
Prepare Ollama
Install and start Ollama, then pull the model used by this example:
ollama pull gemma3:12bAdd the sample image
Place an image named super-agents.png in the same directory as the script, or update image_path to point to your own image.
Run the example
Save the code above as demo_gemma.py, then run:
python demo_gemma.pyFull source: cookbook/90_models/ollama/chat/demo_gemma.py