karthikmulugu08 commited on
Commit
04f7846
·
verified ·
1 Parent(s): d011e18

Improve README: feature drug safety check, all 6 quests, clean architecture

Browse files
Files changed (1) hide show
  1. README.md +91 -63
README.md CHANGED
@@ -21,102 +21,130 @@ tags:
21
  - tiny-titan
22
  ---
23
 
24
- # 🩺 ClinIQ — Privacy-First Clinical Document Assistant
25
 
26
- > **Gradio Build Small Hackathon 2026** · Track: Backyard AI · Model: Qwen2.5-3B-Instruct (≤4B ✅)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
  ## What it does
29
 
30
- ClinIQ lets clinic staff upload patient forms, discharge summaries, and consult notes, then ask
31
- plain-English questions — answered instantly, with full source citations and a live agent trace.
 
 
 
 
 
32
 
33
- **Example questions:**
34
- | Question | Query type |
35
- |----------|-----------|
36
- | *"What medications is this patient on?"* | Structured returns a table |
37
- | *"Do any medications interact with the patient's allergies?"* | Complex multi-hop reasoning |
38
- | *"How have the medications changed between the intake note and the consult?"* | Comparison cross-document |
39
- | *"Summarize the discharge instructions"* | Simple |
 
40
 
41
  ## Architecture
42
 
43
  ```
44
- Upload PDFs/TXT
45
 
46
  Chunking (400 tokens, 80-token overlap)
47
 
48
  Hybrid Retrieval — BM25 (rank_bm25) + Dense (MiniLM-L6-v2) + score fusion
49
 
50
- LangGraph Agent (5 nodes):
51
- classify_query → decompose → retrieve → generate → reflect
52
- ↑_________________________(retry if not grounded, max 2x)
53
 
54
- Qwen2.5-3B-Instruct · llama.cpp Q4_K_M · Modal A10G GPU
55
 
56
- Streaming answer + live trace in custom HTML frontend (gr.Server)
 
 
 
57
  ```
58
 
59
- ## Hackathon Bonus Quests — all 5 achievable
60
 
61
- | Quest | ✅ | How |
62
- |-------|---|-----|
63
- | 🎨 **Off-Brand** | ✅ | `gr.Server` + full custom HTML/CSS/JS — no default Gradio UI |
64
- | 🦙 **Llama Champion** | ✅ | llama.cpp Q4_K_M via Modal (`modal_inference.py`) |
65
- | 📡 **Sharing is Caring** | ✅ | Every query's trace auto-pushed to [HF Hub dataset](https://huggingface.co/datasets/karthikmulugu08/cliniq-traces) |
66
- | 🎯 **Well-Tuned** | ✅ | Qwen2.5-3B-Instruct (instruction fine-tuned, published on Hub) |
67
- | 📓 **Field Notes** | ✅ | [Blog post](./blog_post.md) |
68
 
69
- **Special award targets:** 🐜 Tiny Titan (≤4B) · 🤖 Best Agent · 🎬 Best Demo
 
 
 
 
 
 
 
70
 
71
- ## Smart Clinical Templates
72
 
73
- One-click buttons for the most common clinical queries:
74
- 💊 Medication List · ⚠️ Allergy Summary · 🏥 Diagnoses · 📅 Follow-up Plan · 💓 Vital Signs · 📋 Discharge Summary
75
 
76
- ## Running locally
77
 
78
- ```bash
79
- pip install -r requirements.txt
80
- python app.py # visit http://localhost:7860
81
- ```
82
 
83
- ## Deploying (Modal + HF Space)
84
 
85
- ```bash
86
- # Deploy Modal GPU inference
87
- pip install modal
88
- modal setup # authenticate once
89
- modal deploy modal_inference.py
90
- # → Copy the printed web endpoint URL
91
 
92
- # Then push to HF Space:
93
- bash deploy.sh
94
- ```
95
 
96
- ## Space Secrets
 
97
 
98
- Set in Space Settings Variables & Secrets:
 
99
 
100
- | Secret | Value |
101
- |--------|-------|
102
- | `MODAL_ENDPOINT` | URL from `modal deploy` output |
103
- | `HF_TOKEN` | Your HF write token |
104
- | `HF_DATASET_REPO` | `karthikmulugu08/cliniq-traces` |
105
 
106
- ## Why small models work here
 
 
107
 
108
- Qwen2.5-3B-Instruct is the honest, efficient choice for clinical extraction tasks.
109
- Medications, allergies, diagnoses, and follow-up dates are all **retrievable facts** —
110
- you don't need 70B parameters to find "Metformin 1000mg BID" in a document.
111
- The 3B model runs inference in **~2 seconds** on A10G, costs ~$0.001/query,
112
- and fits entirely within the ≤4B Tiny Titan constraint.
113
 
114
- ## Model
115
 
116
- [Qwen/Qwen2.5-3B-Instruct](https://huggingface.co/Qwen/Qwen2.5-3B-Instruct) — Apache 2.0
117
- Quantized: `bartowski/Qwen2.5-3B-Instruct-GGUF` Q4_K_M (~1.8GB)
118
 
119
- ## Dataset
 
 
120
 
121
- Demo documents are synthetic clinical notes styled after [MTSamples](https://www.mtsamples.com/).
122
- Agent traces from live queries are shared at [karthikmulugu08/cliniq-traces](https://huggingface.co/datasets/karthikmulugu08/cliniq-traces).
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  - tiny-titan
22
  ---
23
 
24
+ # ClinIQ — Privacy-First Clinical Document Assistant
25
 
26
+ > **Gradio Build Small Hackathon 2026** · Qwen2.5-3B-Instruct (Q4_K_M) · llama.cpp on Modal A10G
27
+
28
+ ## The one thing no other clinical RAG does
29
+
30
+ **Proactive Drug Safety Check** — the moment you upload patient documents, ClinIQ automatically scans ALL medications and allergies across every document and flags dangerous combinations. No question needed. A 3B pharmacist runs in the background.
31
+
32
+ Example: upload a discharge summary (Aspirin 81mg prescribed) and an intake note (Aspirin allergy — bronchospasm) from two separate visits. ClinIQ instantly surfaces:
33
+
34
+ ```
35
+ DANGER Aspirin allergy contraindication — patient is prescribed Aspirin 81mg
36
+ but has documented bronchospasm reaction to aspirin
37
+ Recommendation: Switch to Clopidogrel (per cardiology consult)
38
+ ```
39
+
40
+ This catches cross-document drug-allergy conflicts that a human reading one chart at a time would miss.
41
+
42
+ ---
43
 
44
  ## What it does
45
 
46
+ Upload any mix of PDFs and TXT clinical documents, then:
47
+
48
+ - **Proactive safety scan** runs automatically — no question needed
49
+ - **Ask anything** in plain English — answered in ~2 seconds
50
+ - **Structured extraction** returns clean tables (medications, allergies, diagnoses, vitals)
51
+ - **Cross-document reasoning** works across multiple patient records simultaneously
52
+ - **Live agent trace** shows every reasoning step as it happens
53
 
54
+ | Question | Query type | What happens |
55
+ |----------|-----------|-------------|
56
+ | *"List all medications"* | Structured | Returns name/dose/frequency/route table |
57
+ | *"Is it safe to give this patient aspirin?"* | Complex | Multi-hop reasoning across all docs |
58
+ | *"What alternative was recommended instead of aspirin?"* | Simple | Retrieves Clopidogrel from consult note |
59
+ | *"Who is the attending physician?"* | Simple | Direct fact lookup with source |
60
+
61
+ ---
62
 
63
  ## Architecture
64
 
65
  ```
66
+ Upload PDFs / TXT
67
 
68
  Chunking (400 tokens, 80-token overlap)
69
 
70
  Hybrid Retrieval — BM25 (rank_bm25) + Dense (MiniLM-L6-v2) + score fusion
71
 
72
+ LangGraph 5-node Agent:
73
+ classify → decompose → retrieve → build_context → generate → reflect → END
 
74
 
75
+ Qwen2.5-3B-Instruct · llama.cpp Q4_K_M · Modal A10G GPU (~2s/query)
76
 
77
+ Streaming answer + live trace in custom HTML/CSS/JS frontend (gr.Server)
78
+
79
+ PARALLEL: Drug Safety Checker
80
+ regex extraction (no LLM) → Qwen safety reasoning → colour-coded alerts
81
  ```
82
 
83
+ ---
84
 
85
+ ## Hackathon Bonus Quests
 
 
 
 
 
 
86
 
87
+ | Quest | Status | How |
88
+ |-------|--------|-----|
89
+ | Off-Brand | achieved | `gr.Server` — zero default Gradio UI. Full custom HTML/CSS/JS served via FastAPI endpoints |
90
+ | Llama Champion | achieved | llama.cpp Q4_K_M quantization on Modal A10G GPU (`modal_inference.py`) |
91
+ | Sharing is Caring | achieved | Every agent trace auto-pushed to [HF Hub dataset](https://huggingface.co/datasets/karthikmulugu08/cliniq-traces) |
92
+ | Well-Tuned | achieved | Qwen2.5-3B-Instruct — instruction fine-tuned, published on HF Hub |
93
+ | Tiny Titan | achieved | 3B parameter model, ~1.8GB on disk, inference in ~2s |
94
+ | Field Notes | achieved | [Blog post — building ClinIQ](https://huggingface.co/karthikmulugu08) |
95
 
96
+ ---
97
 
98
+ ## Why Qwen2.5-3B works here
 
99
 
100
+ Clinical document extraction is a **retrieval + pattern matching** problem, not a reasoning problem. You don't need 70B parameters to find "Metformin 1000mg BID" in a discharge summary. The 3B model:
101
 
102
+ - Extracts structured medication lists accurately
103
+ - Reasons about drug-allergy interactions given clean lists
104
+ - Runs on A10G in ~2s for ~$0.001/query
105
+ - Fits the Tiny Titan constraint (≤4B) with room to spare
106
 
107
+ The hard work is done by the hybrid retriever and the two-step safety checker (regex extraction first, LLM reasoning second) — the model just needs to synthesize clean inputs.
108
 
109
+ ---
 
 
 
 
 
110
 
111
+ ## Drug Safety Check technical detail
112
+
113
+ Most clinical RAG systems answer questions reactively. ClinIQ's safety checker is proactive:
114
 
115
+ **Step 1 — Regex extraction** (no LLM, instantaneous):
116
+ Scans ALL MEDICATIONS and ALLERGIES sections across all uploaded documents using regex with deduplication. Finds cross-document conflicts a single-document scan would miss.
117
 
118
+ **Step 2 LLM safety reasoning** (Qwen2.5-3B):
119
+ Feeds clean medication and allergy lists to the model. Asks only: "are there dangerous combinations?" Returns structured alerts with DANGER / WARNING / INFO severity.
120
 
121
+ This two-step design is reliable — Step 1 never hallucinates (it's regex), and Step 2 only reasons about clean, extracted lists (not raw document text).
 
 
 
 
122
 
123
+ ---
124
+
125
+ ## Model & Dataset
126
 
127
+ **Model:** [bartowski/Qwen2.5-3B-Instruct-GGUF](https://huggingface.co/bartowski/Qwen2.5-3B-Instruct-GGUF) Q4_K_M Apache 2.0
 
 
 
 
128
 
129
+ **Demo documents:** Synthetic clinical notes (discharge summary, intake note, cardiology consult) styled after MTSamples. Three documents, two patients, intentional cross-document drug-allergy conflict.
130
 
131
+ **Traces:** Live agent traces shared at [karthikmulugu08/cliniq-traces](https://huggingface.co/datasets/karthikmulugu08/cliniq-traces)
 
132
 
133
+ ---
134
+
135
+ ## Running locally
136
 
137
+ ```bash
138
+ pip install -r requirements.txt
139
+ python app.py # http://localhost:7860
140
+ ```
141
+
142
+ ## Deploy (Modal + HF Space)
143
+
144
+ ```bash
145
+ pip install modal
146
+ modal setup
147
+ modal deploy modal_inference.py # prints endpoint URL
148
+
149
+ # Set Space secrets: MODAL_ENDPOINT, HF_TOKEN, HF_DATASET_REPO
150
+ ```