RAG-based medical PDF analyzer โ ask plain-language questions, get grounded answers with citations
Project description
title: MedReport AI emoji: ๐ฅ colorFrom: blue colorTo: indigo sdk: docker app_port: 8000 pinned: false
MedReport AI ๐ฅ
Ask plain-language questions about any medical PDF โ every answer is grounded in the document with exact source citations.
What it does
Upload any medical PDF (discharge summaries, lab reports, referral letters) and ask questions in plain English. The app retrieves the most relevant passages from your document and uses Llama 3.3-70B via Groq to answer โ never hallucinating beyond what the document says.
| Feature | Detail |
|---|---|
| ๐ PDF ingestion | PyMuPDF text extraction, 400-word chunks with 80-word overlap |
| ๐ Semantic search | sentence-transformers all-MiniLM-L6-v2 + FAISS cosine similarity |
| ๐ค LLM | Groq llama-3.3-70b-versatile โ fast, free tier available |
| ๐ฌ Chat UI | Dark-themed glass-morphism interface, source citations, page references |
| ๐ Privacy | Everything runs locally / in your container โ no data leaves your server |
Architecture
PDF Upload
โ
โผ
PyMuPDF โโโบ Text Chunks (400w / 80w overlap)
โ
โผ
SentenceTransformer FAISS IndexFlatIP
(all-MiniLM-L6-v2) โโโบ (cosine similarity)
โ
User Question โโโบ embed โโโโโโโโโโโโโโโบ top-5 chunks
โ
โผ
Groq llama-3.3-70b
(system + context prompt)
โ
โผ
Answer + Citations (page, score)
Quick start
Prerequisites
- Python 3.10+
- A free Groq API key
1. Clone & install
git clone https://github.com/abdullahkousa2/medreport-ai.git
cd medreport-ai
pip install -r requirements.txt
2. Set your API key
cp .env.example .env
# then edit .env and paste your Groq key:
# GROQ_API_KEY=gsk_...
3. Run
uvicorn app.main:app --host 127.0.0.1 --port 8000
Open http://localhost:8000 โ drop in a PDF and start asking questions.
Docker
docker build -t medreport-ai .
docker run -p 8000:8000 -e GROQ_API_KEY=gsk_your_key_here medreport-ai
API Reference
| Endpoint | Method | Description |
|---|---|---|
GET / |
GET | Serve the chat UI |
POST /api/upload |
POST | Upload a PDF โ returns session_id |
POST /api/ask |
POST | Ask a question โ returns answer + citations |
GET /health |
GET | Health check |
Upload
POST /api/upload
Content-Type: multipart/form-data
file: <your-pdf>
{
"session_id": "uuid-string",
"filename": "report.pdf",
"chunks_indexed": 47,
"message": "Indexed 47 text segments โ ready to answer questions."
}
Ask
POST /api/ask
Content-Type: application/json
{ "session_id": "uuid-string", "question": "What medications were prescribed?" }
{
"answer": "According to Source 2, the patient was prescribed Aspirin 75mg...",
"citations": [
{ "source": 1, "page": 4, "excerpt": "...", "score": 0.891 }
]
}
Sample report
A realistic fake cardiac discharge summary (sample_medical_report.pdf) is included for testing. Regenerate it with:
pip install reportlab
python generate_sample_report.py
Project structure
medreport-ai/
โโโ app/
โ โโโ main.py # FastAPI app, routes, static files
โ โโโ rag_engine.py # PDF processing, FAISS index, Groq Q&A
โ โโโ routers/
โ โ โโโ api.py # /api/upload and /api/ask endpoints
โ โโโ static/
โ โโโ index.html # Chat UI
โ โโโ style.css # Design system (dark glass-morphism)
โ โโโ app.js # Upload, chat, citations logic
โโโ Dockerfile
โโโ requirements.txt
โโโ .env.example
โโโ generate_sample_report.py
โโโ sample_medical_report.pdf
Tech stack
| Layer | Technology |
|---|---|
| Web framework | FastAPI 0.111 |
| LLM | Groq API โ llama-3.3-70b-versatile |
| Embeddings | sentence-transformers โ all-MiniLM-L6-v2 |
| Vector search | FAISS IndexFlatIP (cosine via L2-normalised inner product) |
| PDF parsing | PyMuPDF (fitz) |
| Frontend | Vanilla HTML / CSS / JS โ no framework |
| Container | Docker (python:3.10-slim) |
License
MIT โ free to use, modify, and deploy.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file medreport_ai-0.1.0.tar.gz.
File metadata
- Download URL: medreport_ai-0.1.0.tar.gz
- Upload date:
- Size: 21.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2500a7bc5593e475fc07133fd06b7ffaa50ac7513a785ceeaf2ce0216f0d2c86
|
|
| MD5 |
adfe9062a9bac58c10e4c0b807a1101a
|
|
| BLAKE2b-256 |
603bf396268f8445558e474de6ea4e6872aadd68f30e1ec21c1745a649c1e882
|
File details
Details for the file medreport_ai-0.1.0-py3-none-any.whl.
File metadata
- Download URL: medreport_ai-0.1.0-py3-none-any.whl
- Upload date:
- Size: 19.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
995cda7ee036cdf464b51e39d392e559e15d9206cc7a03c9ad73a34711bfd44d
|
|
| MD5 |
b0e83d1ab6beec7f49457e20da1fe158
|
|
| BLAKE2b-256 |
47c918e84cc9dd63c487c12d622d781d1b235d0f4a7d89fa78be7810e1ee44ca
|