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.1.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.1-py3-none-any.whl (19.8 kB view details)

Uploaded Python 3

File details

Details for the file medreport_ai-0.1.1.tar.gz.

File metadata

  • Download URL: medreport_ai-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 ab982bcdac257dbb3163f92e84c1efbd61d9c0902a8adf41ef1953b5c9d6ac66
MD5 4b2d0fce1000261117a641f8090aff6e
BLAKE2b-256 c1fdfd3fe6fd3d0435379fdc67c6f0569781d7944841cb94b286f2beaa3c1e6a

See more details on using hashes here.

File details

Details for the file medreport_ai-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: medreport_ai-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a32e0c2ecaec5ee59cdd44e28ac12a72294be756e7052fbb43fa16fbeafcab41
MD5 f97a064ab911f3fe365dec341adf872e
BLAKE2b-256 5c45283316e384711834e55f77d7e5094d8ff652d7802a4bd7d5b9b8dafaaaef

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