Examples · Programming
Reading an image
Send Gemma the photo of a diagram or of an exercise from your code, and get it explained.
What you need
The example Your first API call in Python: a key and the openai library.
The model
Images are read by Gemma 4 26B (gemma-4-26b). PNG, JPEG, WebP or GIF; at most 8 MB and two images per request.
The program
Put an image in the same folder, for example diagram.png:
import base64
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.ai.itsincom.org/v1",
api_key=os.environ["API_KEY"],
)
with open("diagram.png", "rb") as f:
image = base64.b64encode(f.read()).decode()
answer = client.chat.completions.create(
model="gemma-4-26b",
messages=[{
"role": "user",
"content": [
{"type": "text", "text": "Describe this diagram and tell me whether it contains a mistake."},
{"type": "image_url", "image_url": {"url": f"data:image/png;base64,{image}"}},
],
}],
)
print(answer.choices[0].message.content)
Exercise
- Take a photo of a handwritten exercise and ask for a transcription.
- Ask for the data in the image as a table, or as JSON.
Images are not stored anywhere: they are used only to answer that request.
