--- title: Medical Report Analyzer emoji: 🏥 colorFrom: blue colorTo: green sdk: docker app_file: app.py pinned: true --- # 🏥 AI Medical Report Analyzer An intelligent multi-agent AI system that analyzes medical reports and explains them in simple Hindi or English — making healthcare accessible to every Indian. --- ## 🎯 Problem Statement Every year, millions of Indians receive medical reports they don't understand. Blood reports, X-rays, prescriptions — full of technical jargon that patients can't decode. Most can't afford to visit a doctor just to explain what their report means. This project gives every Indian access to an AI-powered medical assistant that reads their report, explains it simply, and tells them exactly what to do next. --- ## ✨ Features - 📄 **Multi-format support** — PDF, JPG, PNG (photos, scans, digital reports) - 🔬 **Abnormality detection** — flags every value outside normal range with severity - 🧠 **RAG-powered diagnosis** — searches 2457 diseases from medical knowledge base - 💬 **Simple explanations** — no medical jargon, patient-friendly language - 👨‍⚕️ **India-specific advice** — AIIMS, government hospitals, specialist recommendations - 🚦 **Risk levels** — LOW / MEDIUM / HIGH / CRITICAL with urgency timing - 🇮🇳 **Hindi support** — full output in Hindi or English - 📝 **Downloadable report** — color-coded Word document (.docx) - ⚠️ **Responsible AI** — medical disclaimer on every response --- ## 🏗️ Architecture ``` User Input (PDF / Image) ↓ [Agent 1] Document Agent — pypdf + Gemini Vision ↓ [Agent 2] Abnormality Agent — Gemini 2.5 Flash ↓ [Agent 3] RAG Agent — FAISS + sentence-transformers ↓ [Agent 4] Explanation Agent — Gemini + deep-translator ↓ [Agent 5] Specialist Agent — Gemini (India-specific) ↓ [Agent 6] Report Agent — python-docx ↓ Gradio UI + Downloadable Report ``` All agents orchestrated by **LangGraph** with shared TypedDict state. --- ## 🛠️ Tech Stack | Component | Technology | |---|---| | LLM + Vision | Gemini 2.5 Flash (free tier) | | Agent Orchestration | LangGraph | | Vector Database | FAISS (local) | | Embeddings | sentence-transformers/all-MiniLM-L6-v2 | | Medical Dataset | HuggingFace — kamruzzaman-asif/Diseases_Dataset | | PDF Extraction | pypdf | | Translation | deep-translator | | Report Generation | python-docx | | UI | Gradio | | Deployment | HuggingFace Spaces | **Cost: ₹0 — 100% free stack** --- ## 📊 Knowledge Base | Source | Entries | Strength | |---|---|---| | IndianServers split | 796 | India-specific diseases | | QuyenAnh split | 399 | Has treatment data | | symptom2disease split | 1040 | Natural language symptoms | | itachi9604 split | 222 | Additional coverage | | **Total** | **2457** | **2535 FAISS chunks** | --- ## 🚀 Setup & Installation ### Prerequisites - Python 3.11 - Gemini API key (free at [aistudio.google.com](https://aistudio.google.com)) ### Installation ```bash # Clone repository git clone https://github.com/your-username/Medical-Report-Analyzer cd Medical-Report-Analyzer # Create virtual environment python -m venv venv venv\Scripts\activate # Windows source venv/bin/activate # Mac/Linux # Install dependencies pip install -r requirements.txt ``` ### Configuration Create `.env` file: ``` GOOGLE_API_KEY=your_gemini_key_here ``` ### Build Knowledge Base (run once) ```bash python prepare_data.py # Downloads and prepares medical dataset python build_faiss.py # Builds FAISS vector index ``` ### Run ```bash python app.py ``` Open `http://127.0.0.1:7861` in your browser. --- ## 📁 Project Structure ``` Medical-Report-Analyzer/ │ ├── agents/ │ ├── document_agent.py # PDF + image extraction │ ├── abnormality_agent.py # Detects abnormal values │ ├── rag_agent.py # FAISS semantic search │ ├── explanation_agent.py # Simple language explanation │ ├── specialist_agent.py # India-specific doctor advice │ └── report_agent.py # Word document generation │ ├── data/ │ └── medical_knowledge.txt # Built from HuggingFace dataset │ ├── faiss_index/ # Vector index (built locally) ├── generated_reports/ # Patient reports saved here ├── graph.py # LangGraph pipeline ├── build_faiss.py # One-time FAISS builder ├── prepare_data.py # HuggingFace data loader ├── app.py # Gradio UI ├── config.py # Central configuration └── requirements.txt ``` --- ## 🔒 Safety & Disclaimer This system is designed with responsible AI principles: - Every response includes a medical disclaimer - System never claims to diagnose — only guides - Stronger disclaimers for imaging (X-ray, MRI) - Always recommends consulting a qualified doctor - Emergency helplines included in every report --- ## 🗺️ Roadmap **V1 (Current)** - Blood reports, prescriptions, discharge summaries - Hindi + English - 2457 disease knowledge base **V2 (Planned)** - Parallel RAG + web search agents - Voice input support - More Indian languages - WhatsApp integration --- ## 👨‍💻 Author Built by Bhavya as a portfolio project demonstrating: - Multi-agent AI systems with LangGraph - RAG pipelines with FAISS - Multimodal AI with Gemini Vision - Production-grade Python architecture