Load and process images from your local file system:
with open("path/to/image.jpg", "rb") as f: image_data = f.read()response = client.models.generate_content( model="gemini-3.1-pro-preview", contents=[ Part.from_bytes(data=image_data, mime_type="image/jpeg"), "What objects are in this image?" ])print(response.text)
Gemini 3 allows fine-grained control over image processing quality:
from google.genai.types import ( Part, FileData, PartMediaResolution, PartMediaResolutionLevel, GenerateContentConfig)response = client.models.generate_content( model="gemini-3.1-pro-preview", contents=[ Part( file_data=FileData( file_uri="gs://path/to/high-res-image.jpg", mime_type="image/jpeg" ), media_resolution=PartMediaResolution( level=PartMediaResolutionLevel.MEDIA_RESOLUTION_HIGH ) ), "Read the small text in this image." ])
Higher resolution settings increase token usage and latency but improve accuracy for fine details and small text.
response = client.models.generate_content( model="gemini-3.1-pro-preview", contents=[ Part.from_uri( file_uri="gs://cloud-samples-data/generative-ai/video/pixel_phone.mp4", mime_type="video/mp4" ), "Summarize the main events in this video." ])print(response.text)
response = client.models.generate_content( model="gemini-3.1-pro-preview", contents=[ Part.from_uri( file_uri="gs://path/to/video1.mp4", mime_type="video/mp4", ), Part.from_uri( file_uri="gs://path/to/video2.mp4", mime_type="video/mp4", ), "What are the differences between these two videos?" ])
response = client.models.generate_content( model="gemini-3.1-pro-preview", contents=[ Part.from_uri( file_uri="gs://cloud-samples-data/generative-ai/audio/podcast.mp3", mime_type="audio/mpeg" ), "Transcribe this audio and provide a summary." ])print(response.text)
response = client.models.generate_content( model="gemini-3.1-pro-preview", contents=[ Part.from_uri( file_uri="gs://cloud-samples-data/generative-ai/pdf/2312.11805v3.pdf", mime_type="application/pdf" ), "Summarize the key findings of this research paper." ])
response = client.models.generate_content( model="gemini-3.1-pro-preview", contents=[ Part.from_uri( file_uri="https://cloud.google.com/vertex-ai/docs", mime_type="text/html" ), "Summarize the key features described on this page." ])
chat = client.chats.create( model="gemini-3.1-pro-preview")# First turn with imageresponse = chat.send_message([ Part.from_uri( file_uri="gs://path/to/chart.png", mime_type="image/png" ), "What does this chart show?"])print(response.text)# Follow-up without image (maintains context)response = chat.send_message("What were the peak values?")print(response.text)