Build a real web app where users upload a PDF and ask questions about it. Powered by Gemini + Streamlit — production-ready in under 100 lines.
A web app where users upload any PDF (book, report, contract) and chat with it — ask questions, get summaries, find key facts. All powered by Google Gemini and built with Streamlit.
This is one of the most useful AI patterns — Retrieval Augmented Generation (RAG) at its simplest. The user uploads a document, the app sends both the document and their question to Gemini, and Gemini answers using only that document's content. Let's build it.
Create a folder pdf-chat. Open in VS Code. Create a file app.py. Open the terminal.
We need three libraries: Streamlit (web UI), Gemini SDK, and PyPDF (to read PDFs):
This takes about 30 seconds.
If you don't have one yet:
Completely free, no card needed.
Streamlit lets you build web apps with just Python. Add this to app.py:
Run it:
A browser tab opens at http://localhost:8501 with your UI. Magic, right?
Add a function to extract text from the uploaded PDF:
This walks every page of the PDF and combines the text into one big string.
Now wire up Gemini. Add at the top of app.py:
Then at the bottom of the file:
Save and Streamlit will hot-reload. Upload a PDF, type a question, watch it work.
Let's make it nicer. Add a sidebar with instructions and show a preview of the loaded PDF:
Small touches like a spinner during loading, a sidebar, and success messages make a huge UX difference.
Streamlit apps deploy in minutes on Streamlit Community Cloud — free for public apps:
requirements.txt with your libs)You'll get a public URL like yourname-pdfchat.streamlit.app. Share it with anyone.
st.secrets["GEMINI_KEY"] instead.You just built one of the most useful AI app patterns — RAG (Retrieval Augmented Generation) in its simplest form. This is the foundation behind ChatPDF, NotebookLM, and many enterprise AI tools.
Spotted a bug, broken code, or something that doesn't look right? Tell us what's off and we'll fix it.