I Deployed a PDF Summarizer Using Gemini on Google Cloud. Here's What the Setup Looks Like.
Google's Vertex AI quickstart gets you to a working app fast. Getting it deployed with auth on Cloud Run takes a bit more. Here's the full path.
I wanted to try Vertex AI and Gemini Pro. Google has a quickstart for a PDF summarizer — Flask app, upload a PDF, get a summary back. I followed it. The app worked in about an hour.
Then I wanted to actually deploy it somewhere. That part took longer. Here's what the full path looks like, including the things the quickstart skips.
What the app does
It's a Flask app with two pages. The first page has a file upload form and a text box for instructions. You upload a PDF and type what you want — "summarize this", "extract the key decisions", anything. The second page shows the result.
Under the hood: LangChain's PyPDFLoader splits the PDF into pages and combines the text. That combined text goes into a prompt with your instruction. The prompt hits Vertex AI's Gemini Pro. The response comes back as markdown and gets rendered in the browser.
loader = PyPDFLoader(pdf_temp_filename)
pages = loader.load_and_split()
combined_text = "\n\n".join([p.page_content for p in pages])
prompt = f"{instruction} Use information from the PDF to respond.\n\nPDF:\n{combined_text}"
response = model.generate_content(prompt, generation_config=generation_config)The token limit gotcha
Gemini Pro has a token limit. The app checks word count before sending the prompt. If the PDF is over 18,500 words, it returns an error message instead of calling the model.
Why 18,500 words? A rough conversion: one word is about 1.66 tokens. So 18,500 words is roughly 30,000 tokens, which stays under the model's context limit with room for the instruction and the response.
It's a blunt check. A better version would chunk the document and summarize in passes. For the quickstart this is fine — it tells you clearly when the document is too long.
The model config
Three settings matter here. Temperature at 0.3 keeps the output factual — low creativity, stays close to what's in the PDF. Top-p at 0.6 tightens the token selection further. Max output tokens at 4,096 is enough for a full summary of most documents.
generation_config = GenerationConfig(
temperature=0.3,
top_p=0.6,
candidate_count=1,
max_output_tokens=4096,
)For a summarizer you want low temperature. You're not asking the model to be creative. You're asking it to compress what's already there.
Deploying to Cloud Run
The app comes with a Dockerfile. It's a standard Python 3.11 image, copies the code, installs requirements, exposes port 8080. Cloud Run expects port 8080 by default so this works without changes.
FROM python:3.11
WORKDIR /app
COPY . ./
RUN pip install -r requirements.txt
EXPOSE 8080
ENTRYPOINT ["python3", "app.py"]
Build the image, push it to Google Artifact Registry, deploy to Cloud Run. The service needs a PROJECT_ID environment variable set so Vertex AI knows which Google Cloud project to bill. You set that in the Cloud Run service config, not in the Dockerfile.
gcloud builds submit --tag gcr.io/YOUR_PROJECT_ID/summarizer-app
gcloud run deploy summarizer-app \
--image gcr.io/YOUR_PROJECT_ID/summarizer-app \
--platform managed \
--region us-central1 \
--set-env-vars PROJECT_ID=YOUR_PROJECT_ID
Adding IAP auth
By default, Cloud Run services are either fully public or require a Google account with the right IAM role. IAP (Identity-Aware Proxy) adds a proper login gate in front of the service. Anyone who tries to open the URL gets redirected to Google sign-in first.
To enable it: set the Cloud Run service to require authentication, then put a load balancer in front of it with IAP enabled. You add the Google accounts that should have access in the IAP settings. After that, only those accounts can reach the app.
The quickstart skips this step. For anything beyond a personal experiment, you want it.
What I'd change
- Chunk long documents and summarize in passes instead of hard-cutting at 18,500 words
- Add streaming so the response appears word by word instead of all at once after a delay
- Store results in Cloud Storage instead of the session so users can revisit them
- Switch from Gemini Pro to Gemini 1.5 or 2.0 for the larger context window
The quickstart gives you the core loop fast. The deployment work — Docker, Cloud Run, IAP — is where most of the real learning happened. That part isn't in the tutorial.
Comments