Skip to main content

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.

Python FastAPI Groq FAISS Docker License


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

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

medreport_ai-0.1.0.tar.gz (21.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

medreport_ai-0.1.0-py3-none-any.whl (19.8 kB view details)

Uploaded Python 3

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

Hashes for medreport_ai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2500a7bc5593e475fc07133fd06b7ffaa50ac7513a785ceeaf2ce0216f0d2c86
MD5 adfe9062a9bac58c10e4c0b807a1101a
BLAKE2b-256 603bf396268f8445558e474de6ea4e6872aadd68f30e1ec21c1745a649c1e882

See more details on using hashes here.

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

Hashes for medreport_ai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 995cda7ee036cdf464b51e39d392e559e15d9206cc7a03c9ad73a34711bfd44d
MD5 b0e83d1ab6beec7f49457e20da1fe158
BLAKE2b-256 47c918e84cc9dd63c487c12d622d781d1b235d0f4a7d89fa78be7810e1ee44ca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page