A clinical decision support system that combines FHIR-compliant patient data parsing, retrieval-augmented generation (RAG), and a fine-tuned Qwen 2.5 language model to deliver accurate, context-aware medical responses.
| Feature | Description |
|---|---|
| π FHIR Patient Parser | Validates and structures patient JSON into clinical context |
| π RAG Pipeline | FAISS-powered vector search over medical documents |
| π§ Fine-tuned LLM | Qwen 2.5 with LoRA adapters trained on medical QA data |
| π REST API | FastAPI endpoints for patient parsing, queries, and summaries |
| π₯οΈ Web Interface | Gradio UI for interactive clinical question-answering |
| π Evaluation Suite | ROUGE, BLEU, and Exact Match metrics |
βββββββββββββββββββ ββββββββββββββββ βββββββββββββββββββ
β Patient JSON ββββββΆβ FHIR Parser ββββββΆβ Patient Context β
β (FHIR-compat) β β β β β
βββββββββββββββββββ ββββββββββββββββ ββββββββββ¬βββββββββ
β
βββββββββββββββββββ ββββββββββββββββ β
β User Question ββββββΆβ RAG (FAISS) ββββββββββββββββ€
β β β β β
βββββββββββββββββββ ββββββββββββββββ βΌ
ββββββββββββββββββββββ
β Qwen 2.5 (LoRA) β
β Clinical Inference β
βββββββββββ¬βββββββββββ
β
βΌ
ββββββββββββββββββββββ
β Clinical Answer β
ββββββββββββββββββββββ
- Python 3.11+
- uv (recommended) or pip
# Clone the repository
git clone https://github.com/your-username/MedicLLM.git
cd MedicLLM
# Create virtual environment and install dependencies
uv venv
.venv\Scripts\activate # Windows
# source .venv/bin/activate # macOS/Linux
uv syncMedicLLM/
βββ app/
β βββ api.py # FastAPI REST endpoints
β βββ fhir_parser.py # FHIR patient data parser
β βββ inference.py # LLM inference with LoRA
β βββ rag.py # RAG pipeline (FAISS + embeddings)
β βββ schemas.py # Pydantic request/response models
βββ training/
β βββ config.py # Training hyperparameters
β βββ dataset.py # Medical QA dataset loader
β βββ train.py # Fine-tuning with TRL + PEFT
β βββ evaluate.py # ROUGE / BLEU evaluation
βββ data/
β βββ medical_docs/ # Medical reference documents
β βββ medical_qa.json # Training dataset
β βββ patient_*.json # Sample patient records
βββ tests/
β βββ test_fhir_parser.py
βββ gradio_app.py # Interactive web UI
βββ pyproject.toml # Project configuration
uv run python -m app.apiServer runs at
http://localhost:8000
uv run python gradio_app.pyGradio interface opens at
http://localhost:7860
Health Check:
curl http://localhost:8000/healthAsk a Clinical Question:
curl -X POST http://localhost:8000/query \
-H "Content-Type: application/json" \
-d '{
"question": "What should be monitored for this patient?",
"patient_data": {
"patient_id": "P1001",
"patient": {"age": 65, "gender": "male"},
"conditions": ["Type 2 Diabetes", "Hypertension"],
"medications": ["Metformin 500mg", "Lisinopril 10mg"],
"observations": ["HbA1c: 7.2%"],
"allergies": ["Penicillin"]
}
}'Generate Patient Summary:
curl -X POST http://localhost:8000/summary \
-H "Content-Type: application/json" \
-d '{
"patient_data": {
"patient_id": "P1001",
"patient": {"age": 65, "gender": "male"},
"conditions": ["Type 2 Diabetes"],
"medications": ["Metformin 500mg"]
}
}'Train on Kaggle with GPU acceleration:
cd training
python train.pyTraining Configuration (training/config.py):
| Parameter | Value |
|---|---|
| Base Model | Qwen/Qwen2.5-3B-Instruct |
| LoRA Rank | 16 |
| LoRA Alpha | 32 |
| Epochs | 3 |
| Learning Rate | 2e-4 |
| Batch Size | 4 |
uv run python training/evaluate.pyComputes:
- ROUGE-1 / ROUGE-2 / ROUGE-L β n-gram overlap with reference answers
- BLEU β translation-quality scoring
- Exact Match β strict correctness metric
| Endpoint | Method | Description |
|---|---|---|
/health |
GET | Health check and model status |
/patient |
POST | Parse and validate patient JSON |
/query |
POST | Ask a clinical question with optional patient context |
/summary |
POST | Generate a clinical patient summary |
- Model: Qwen 2.5 3B with LoRA via PEFT
- Training: TRL SFTTrainer, Hugging Face Accelerate
- RAG: FAISS, Sentence Transformers (
all-MiniLM-L6-v2) - API: FastAPI + Uvicorn
- UI: Gradio
- Evaluation: rouge-score, NLTK BLEU
Built with care for clinical intelligence