Data extraction and summarization in Low-Resource Medical NLP Pipelines
# MedicalRAG
A medical document analysis system that turns PDFs into structured clinical data diseases, lab results, ICD-10 codes, and a short summary with a focus on **reliability and reduced token consumption**.
Built for low-resource environments: CPU-only hardware, small local models, and cloud deployment without loading gigabytes of NLP weights onto the server.
---
## What it does
Upload a medical PDF and the system returns:
- **Diseases** with confidence scores and ICD-10 codes
- **Lab results** with values, units, and normal/abnormal flags
- **A plain-text summary** written from the extracted data (not from a raw document dump)
The key idea: extract facts first with specialized tools, then let the LLM summarize only what was already found. This cuts down on made-up details.
---
## Two ways to run it
MedicalRAG supports two modes, controlled by `APP_ENV`:
| Mode | Best for | LLM | NLP stack |
|------|----------|-----|-----------|
| **Local (dev)** | Research, offline use, tuning | Qwen 2.5 via llama.cpp on your machine | Full pipeline: PubMedBERT, medSpaCy, Docling |
| **Production** | Hosted deployment (Render, Vercel, etc.) | Groq cloud API | Lightweight: PyMuPDF + Groq prompts |
Read the architecture guides for details:
- **Production architecture** cloud pipeline, Groq, deployment
- **Local LLM architecture** offline models, Redis worker, llama.cpp
---
## Quick start
### Production (minimal setup)
1. Clone the repo and install production dependencies:
```bash
pip install -r requirements-prod.txt
```
2. Copy `.env.example` to `apps/api/.env` and set `APP_ENV=production` plus your `GROQ_API_KEY`.
3. Start the API from `apps/api`:
```bash
uvicorn app.main:app --reload
```
4. For the frontend:
```bash
cd apps/web/frontend
npm install
npm start
```
### Local development (full pipeline)
You need Redis, Ollama (for model files), and the dev dependencies. See the full walkthrough in **docs/SETUP.md**.
Short version three terminals:
```b …