Agent with GCS File Input

Code

1"""GCS file input with Gemini.
2
3Pass files directly from Google Cloud Storage (gs://) without downloading.
4Supports files up to 2GB. Requires Vertex AI authentication.
5"""
6
7from kern.agent import Agent
8from kern.media import File
9from kern.models.google import Gemini
10
11agent = Agent(
12 model=Gemini(
13 id="gemini-2.0-flash",
14 vertexai=True,
15 ),
16 markdown=True,
17)
18
19agent.print_response(
20 "Summarize this document and extract key insights.",
21 files=[
22 File(
23 url="gs://cloud-samples-data/generative-ai/pdf/2312.11805v3.pdf",
24 mime_type="application/pdf",
25 )
26 ],
27)

Usage

Set up your virtual environment

1uv venv --python 3.12
2source .venv/bin/activate
1uv venv --python 3.12
2.venv\Scripts\activate

Set up Vertex AI

1gcloud auth application-default login
2export GOOGLE_CLOUD_PROJECT="your-project-id"
3export GOOGLE_CLOUD_LOCATION="us-central1"

Install dependencies

1pip install -U google-genai kern-ai

Run Agent

1python cookbook/11_models/google/gemini/gcs_file_input.py