Spaces:
Running
Running
Commit
Β·
ff04da1
1
Parent(s):
8690055
README.md Updated.
Browse files
README.md
CHANGED
@@ -11,4 +11,133 @@ license: mit
|
|
11 |
short_description: Clinical Query Answering with RAG + MIMIC-IV Notes.
|
12 |
---
|
13 |
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
short_description: Clinical Query Answering with RAG + MIMIC-IV Notes.
|
12 |
---
|
13 |
|
14 |
+
# π©Ί RAGnosis β Clinical Reasoning via Retrieval-Augmented Generation
|
15 |
+
|
16 |
+
[](LICENSE)
|
17 |
+
[](https://www.python.org/)
|
18 |
+
[](https://huggingface.co/spaces/asadsandhu/RAGnosis)
|
19 |
+
[](https://github.com/asadsandhu/RAG-Diagnostic-Assistant)
|
20 |
+
|
21 |
+
> βοΈ A fully offline-capable, Gradio-powered RAG assistant trained on **annotated clinical notes** from the [MIMIC-IV-Ext-DiReCT](https://github.com/asadsandhu/RAG-Diagnostic-Assistant/blob/main/mimic-iv-ext-direct-1.0.0.zip) dataset to perform explainable diagnostic reasoning.
|
22 |
+
|
23 |
+
---
|
24 |
+
|
25 |
+
## πΌοΈ Demo
|
26 |
+
|
27 |
+
Try it live on **Hugging Face Spaces** π
|
28 |
+
π https://huggingface.co/spaces/asadsandhu/RAGnosis
|
29 |
+
|
30 |
+
<p align="center">
|
31 |
+
<img src="assets/demo.png" alt="Demo" width="750">
|
32 |
+
</p>
|
33 |
+
|
34 |
+
---
|
35 |
+
|
36 |
+
## βοΈ Tech Stack
|
37 |
+
|
38 |
+
| Layer | Details |
|
39 |
+
|--------------|-------------------------------------------------------------------------|
|
40 |
+
| π§ Model | [`Nous-Hermes-2-Mistral-7B-DPO`](https://huggingface.co/NousResearch/Nous-Hermes-2-Mistral-7B-DPO) |
|
41 |
+
| π₯ Dataset | [`MIMIC-IV-Ext-DiReCT`](https://github.com/asadsandhu/RAG-Diagnostic-Assistant/blob/main/mimic-iv-ext-direct-1.0.0.zip) |
|
42 |
+
| π Retriever | FAISS + SentenceTransformers (`all-MiniLM-L6-v2`) |
|
43 |
+
| π» Frontend | Gradio (Hugging Face Spaces) |
|
44 |
+
| π§ Backend | PyTorch + Transformers + BitsAndBytes |
|
45 |
+
|
46 |
+
---
|
47 |
+
|
48 |
+
## π Features
|
49 |
+
|
50 |
+
- π Top-k document retrieval from real annotated clinical notes
|
51 |
+
- π Reasoning based on structured diagnostic chains
|
52 |
+
- π§ GPT-style generation from LLM (Mistral 7B) without internet dependency
|
53 |
+
- π§Ύ Clean Gradio interface for natural medical queries
|
54 |
+
- π§ Answers explained like a clinical reasoning expert
|
55 |
+
|
56 |
+
---
|
57 |
+
|
58 |
+
## β‘ Example Prompt
|
59 |
+
|
60 |
+
> *Patient presents with fatigue, orthopnea, and lower extremity edema.*
|
61 |
+
|
62 |
+
π¬ **Model response:**
|
63 |
+
> Based on the patient's symptoms and context, the most likely diagnosis is **congestive heart failure (CHF)**...
|
64 |
+
|
65 |
+
---
|
66 |
+
|
67 |
+
## π How It Works
|
68 |
+
|
69 |
+
### β
Step 1: Preprocessing
|
70 |
+
- Extract chains from `samples/` and `diagnostic_kg/`
|
71 |
+
- Build retrievable clinical observations + diagnoses
|
72 |
+
|
73 |
+
### β
Step 2: Retrieval (FAISS)
|
74 |
+
- Embed notes using `MiniLM-L6-v2`
|
75 |
+
- Save as FAISS index β [`faiss_index.bin`](https://github.com/asadsandhu/RAG-Diagnostic-Assistant/blob/main/faiss_index.bin)
|
76 |
+
- Paired with β [`retrieval_corpus.csv`](https://github.com/asadsandhu/RAG-Diagnostic-Assistant/blob/main/retrieval_corpus.csv)
|
77 |
+
|
78 |
+
### β
Step 3: Generation
|
79 |
+
- Format prompt in `[INST]` syntax
|
80 |
+
- Generate diagnosis using `Nous-Hermes-2-Mistral-7B-DPO`
|
81 |
+
|
82 |
+
---
|
83 |
+
|
84 |
+
## π§ͺ Run Locally
|
85 |
+
|
86 |
+
```bash
|
87 |
+
# 1. Clone the repository
|
88 |
+
git clone https://github.com/asadsandhu/RAG-Diagnostic-Assistant.git
|
89 |
+
cd RAG-Diagnostic-Assistant
|
90 |
+
|
91 |
+
# 2. Install dependencies
|
92 |
+
pip install -r requirements.txt
|
93 |
+
|
94 |
+
# 3. Run the app
|
95 |
+
python app.py
|
96 |
+
````
|
97 |
+
|
98 |
+
βοΈ Required files:
|
99 |
+
|
100 |
+
* [`retrieval_corpus.csv`](https://github.com/asadsandhu/RAG-Diagnostic-Assistant/blob/main/retrieval_corpus.csv)
|
101 |
+
* [`faiss_index.bin`](https://github.com/asadsandhu/RAG-Diagnostic-Assistant/blob/main/faiss_index.bin)
|
102 |
+
|
103 |
+
---
|
104 |
+
|
105 |
+
## π Folder Structure
|
106 |
+
|
107 |
+
```
|
108 |
+
RAG-Diagnostic-Assistant/
|
109 |
+
βββ app.py
|
110 |
+
βββ faiss_index.bin
|
111 |
+
βββ retrieval_corpus.csv
|
112 |
+
βββ requirements.txt
|
113 |
+
βββ assets/
|
114 |
+
β βββ demo.png
|
115 |
+
βββ README.md
|
116 |
+
```
|
117 |
+
|
118 |
+
---
|
119 |
+
|
120 |
+
## π€ Author
|
121 |
+
|
122 |
+
Built with β€οΈ by **Asad Ali**
|
123 |
+
π [LinkedIn β @asadsandhu0](https://www.linkedin.com/in/asadsandhu0)
|
124 |
+
π [Hugging Face β RAGnosis](https://huggingface.co/spaces/asadsandhu/RAGnosis)
|
125 |
+
|
126 |
+
---
|
127 |
+
|
128 |
+
## π License
|
129 |
+
|
130 |
+
This project is under the [MIT License](LICENSE).
|
131 |
+
|
132 |
+
---
|
133 |
+
|
134 |
+
## π Acknowledgments
|
135 |
+
|
136 |
+
* MIMIC-IV-Ext-DiReCT: Annotated diagnostic data
|
137 |
+
* Hugging Face Transformers + Gradio
|
138 |
+
* Facebook Research β FAISS
|
139 |
+
* Nous Research β Instruction-tuned Mistral model
|
140 |
+
|
141 |
+
---
|
142 |
+
|
143 |
+
> β οΈ *Disclaimer: This project is for research/demo use only. Not intended for clinical decision-making.*
|