Using Gemini in Education
Source notebook
Repo path:
gemini/use-cases/education/use_cases_for_education.ipynb· Open on GitHub · intro
Demonstrates Gemini education prompts across text, math, images, multiple images, and video.
Summary
This notebook teaches how to use the Google Gen AI SDK with the Gemini API in Vertex AI for education-oriented tasks. It initializes a Vertex AI-backed GenAI client, defines a small generation helper, and runs prompts for reasoning, summarization, translation, correction, math, image understanding, multi-image comparison, and video understanding. The workflow shows text-only and multimodal calls using URL and Cloud Storage media parts.
Key code patterns
Initialize Vertex AI GenAI client
from google import genai
PROJECT_ID = os.environ.get("GOOGLE_CLOUD_PROJECT")
LOCATION = os.environ.get("GOOGLE_CLOUD_REGION", "us-central1")
client = genai.Client(vertexai=True, project=PROJECT_ID, location=LOCATION)Uses the Google Gen AI SDK against Vertex AI with project and region settings.
Reusable content generation helper
def generate_content(model_id: str, contents: list | str) -> str:
return client.models.generate_content(
model=model_id,
contents=contents,
config=GenerateContentConfig(max_output_tokens=8192),
).textCentralizes Gemini calls and sets a maximum output token limit for responses.
Image input from URI
image_abacus = Part.from_uri(
file_uri="https://images.unsplash.com/photo-1548690596-f1722c190938?...",
mime_type="image/jpeg",
)
contents = ["Describe this image in a short sentence:", image_abacus]Shows how to pass remote image content with text prompts for visual reasoning.
Video input from Cloud Storage
video = Part.from_uri(
file_uri="gs://cloud-samples-data/video/animals.mp4",
mime_type="video/mp4",
)
contents = [prompt, video]Shows Gemini video understanding with timestamped questions over a GCS video file.
Models & APIs used
- Models: gemini-3.5-flash
- APIs / services: Vertex AI, Gemini API in Vertex AI, Cloud Storage
- SDKs / libraries:
google-genai
When to use this
Use this pattern to prototype education workflows that need Gemini text, image, and video reasoning through Vertex AI.
Gotchas & caveats
- This tutorial uses billable Vertex AI components.
- Colab requires explicit Google Cloud authentication; Vertex AI Workbench does not.
- PROJECT_ID must be set directly or available as GOOGLE_CLOUD_PROJECT.
- LOCATION defaults to us-central1 when GOOGLE_CLOUD_REGION is unset.
- The helper function signature shown does not accept temperature, but one later call passes temperature=1.0.
- The notebook notes that large language models can hallucinate math results and recommends step-by-step prompts or calculator libraries for advanced math.
- Video files are sampled at 1 frame per second, with video and audio samples analyzed with timestamps.
Best practices
- Use a low default temperature for more consistent responses.
- Use few-shot examples to guide response structure and formatting for text correction.
- Ask for step-by-step reasoning to reduce hallucinations in math tasks.
- Use structured output requests such as JSON lists or tables when asking detailed questions.
- Ask video questions using the video only and request timestamps plus source type such as image, text, or speech.
Related
- Concepts: Gemini Capabilities · Vision · Applied Use Cases
- Entities: Vertex AI · Google GenAI SDK · Cloud Storage · Gemini
- Area: Gemini Notebooks
- Best practices: Gemini Capabilities - Best Practices · Vision - Best Practices · Applied Use Cases - Best Practices