AI-powered Document Analysis Web Application
Leverage the power of Large Language Models (LLMs) to instantly extract insights and answer questions from PDF and TXT documents.
The AI Document Analyzer is a Streamlit-based web app that allows users to upload documents and interact with their content using cutting-edge AI models.
Whether you want to analyze reports, research papers, or any text-based content, this tool provides real-time, context-aware answers.
- 📂 Universal Document Upload – Supports PDF and TXT formats
- 🤖 Dual AI Backend –
- Ollama (Offline): Run locally without internet
- Gemini (Free Cloud): Google cloud-based AI
- ⚡ Real-time AI Analysis – Ask questions and get instant answers
- 🖥 User-Friendly Interface – Clean, intuitive Streamlit UI
- 🔒 Safe and Lightweight – Minimal setup, optional cloud use
| File Type | Extraction Method |
|---|---|
| PyPDF2 library for structured text extraction | |
| TXT | Direct UTF-8 file reading |
⚠️ Note: Scanned or image-based PDFs may not extract text correctly.
- Runs locally on your machine
- Uses the
tinyllamamodel - Works without internet once installed
- Requires Ollama service running
- Uses Google Gemini Flash model (
gemini-flash-latest) - Requires internet connection
- Requires GEMINI_API_KEY environment variable
- Free-tier friendly and stable for small/medium documents
- Python 3.7+
pippackage manager
pip install streamlit PyPDF2 google-genaiInstall Ollama: https://ollama.ai/
Pull the required model:
ollama pull tinyllamaStart Ollama service:
ollama serveGet a free API key: https://makersuite.google.com/app/apikey
Set environment variable:
# Windows
set GEMINI_API_KEY=your_api_key_here
# Linux/Mac
export GEMINI_API_KEY=your_api_key_hereStart the app:
streamlit run app.pyOpen browser at http://localhost:8501
- Upload PDF or TXT document
- Select AI backend:
- Ollama (Offline) → Local processing
- Gemini (Free Cloud) → Cloud-based processing
- Enter your question about the document
- Click Analyze Document to get AI-powered answers
doc-analysier/
├── app.py # Main Streamlit app
├── README.md # Documentation
└── .git/ # Git repository files| Function | Description |
|---|---|
extract_text_from_file() |
Extract text from PDF/TXT |
ask_ollama() |
Query local Ollama LLM |
ask_gemini() |
Query Google Gemini API |
main() |
Handles Streamlit UI and workflow |
- PDF extraction may fail on scanned or image-based documents
- Ollama tinyllama model has ~3000 character context limit
- Gemini API has free-tier rate limits
- Very large documents may need truncation
| Issue | Solution |
|---|---|
| "PyPDF2 not installed" | Run pip install PyPDF2 |
| "Ollama not found" | Install Ollama and start the service |
| "GEMINI_API_KEY not found" | Set environment variable correctly |
| "Unsupported file type" | Upload PDF or TXT only |
| "PDF text extraction fails" | Check if PDF is image-based or complex |
- Python & Streamlit → UI framework
- PyPDF2 → PDF text extraction
- google-genai → Gemini cloud AI integration
- Subprocess → Ollama CLI interaction
- Pathlib & Tempfile → File management
- Retrieval-Augmented Generation (RAG) with vector embeddings
- Multi-document support
- Summarization and highlighting
- Chat-like interface for document Q&A
MIT License – Open source and free to use, modify, and redistribute.