--- title: RAGnosis emoji: ๐Ÿง  colorFrom: red colorTo: indigo sdk: gradio sdk_version: 5.36.2 app_file: app.py pinned: false license: mit short_description: Clinical Query Answering with RAG + MIMIC-IV Notes. --- # ๐Ÿง  RAGnosis โ€“ Clinical Reasoning via Retrieval-Augmented Generation [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE) [![Python](https://img.shields.io/badge/Python-3.10+-blue.svg)](https://www.python.org/) [![Hugging Face](https://img.shields.io/badge/HuggingFace-RAGnosis-blue?logo=huggingface)](https://huggingface.co/spaces/asadsandhu/RAGnosis) [![GitHub Repo](https://img.shields.io/badge/GitHub-asadsandhu/RAG--Diagnostic--Assistant-black?logo=github)](https://github.com/asadsandhu/RAG-Diagnostic-Assistant) > โš•๏ธ A CPU-friendly RAG assistant for explainable clinical diagnosis, built using annotated 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. --- ## ๐Ÿ–ผ๏ธ Live Demo Try it on **Hugging Face Spaces** (CPU-based, ~500s latency) ๐Ÿ‘‰ : ๐Ÿ”— https://huggingface.co/spaces/asadsandhu/RAGnosis

Demo

--- ## โš™๏ธ Technical Stack | Component | Details | |----------------|-------------------------------------------------------------------------| | ๐Ÿง  Model | [`BioMistral/BioMistral-7B`](https://huggingface.co/BioMistral/BioMistral-7B) | | ๐Ÿฅ Dataset | [`MIMIC-IV-Ext-DiReCT`](https://github.com/asadsandhu/RAG-Diagnostic-Assistant/blob/main/mimic-iv-ext-direct-1.0.0.zip) | | ๐Ÿ” Retrieval | FAISS + SentenceTransformers (`all-MiniLM-L6-v2`) | | ๐Ÿ’ฌ Interface | Gradio (Runs on Hugging Face Spaces) | | โš™๏ธ Backend | PyTorch + Transformers (CPU inference) | --- ## ๐Ÿฉบ Key Features - ๐Ÿ”Ž Top-k clinical note retrieval from structured diagnostic chains - ๐Ÿง  Diagnosis generation using `BioMistral-7B` without GPU - ๐Ÿ—‚๏ธ MIMIC-IV-Ext-DiReCT backed medical reasoning - ๐Ÿ’ฌ Natural query input and interpretable LLM output - โœ… Optimized for Hugging Face's free CPU tier (16GB RAM) --- ## ๐Ÿงช Example Prompt > *patient is experiencing shortness of breath* ๐Ÿ’ฌ **Model response:** > Shortness of breath is a common symptom that can be caused by a variety of respiratory conditions. The differential diagnosis for shortness of breath includes asthma, chronic obstructive pulmonary disease (COPD), congestive heart failure, pneumonia, and pneumothorax. In order to determine the cause of the shortness of breath, it is important to consider the patient's medical history, physical examination findings, and diagnostic testing results. For example, if the patient has a history of asthma and is experiencing wheezing and a prolonged expiratory phase on examination, this would suggest asthma as the cause of the shortness of breath. On the other hand, if the patient has a history of congestive heart failure and is experiencing orthopnea, crackles on auscultation, and a history of edema, this would suggest congestive heart failure as the cause of the shortness of breath. --- ## ๐Ÿ”ง Under the Hood ### ๐Ÿง  Step 1: Retrieval - Sentence embeddings (`MiniLM-L6-v2`) - FAISS indexing โ†’ [`faiss_index.bin`](https://github.com/asadsandhu/RAG-Diagnostic-Assistant/blob/main/faiss_index.bin) - Source: [`retrieval_corpus.csv`](https://github.com/asadsandhu/RAG-Diagnostic-Assistant/blob/main/retrieval_corpus.csv) ### ๐Ÿงฑ Step 2: Prompt Construction - Clinical query + retrieved chunks form an instruction prompt ### ๐Ÿงฌ Step 3: Generation - Uses `BioMistral/BioMistral-7B` - Generated on CPU (expect ~500 seconds) --- ## โš ๏ธ Note on Performance | Feature | Hugging Face (CPU) | Colab / Local (GPU) | |--------------|----------------------------|--------------------------------------| | Model Used | `BioMistral-7B` | `Nous-Hermes-2-Mistral-7B-DPO` | | Speed | ~500 seconds/query ๐Ÿข | ~10 seconds/query โšก | | Accuracy | โœ… Good | โœ… Great | | Requirements | 1 CPU (free tier) | CUDA GPU (Colab/Kaggle/local) | > Want faster responses? Use the [GPU version on GitHub](https://github.com/asadsandhu/RAG-Diagnostic-Assistant) with `app.py`. --- ## โš™๏ธ Run It Locally (GPU Recommended) ```bash # 1. Clone the repository git clone https://github.com/asadsandhu/RAG-Diagnostic-Assistant.git cd RAG-Diagnostic-Assistant # 2. Install dependencies pip install -r requirements.txt # 3. Run the app (auto-detects GPU) python app.py ```` Required files (already in repo): * โœ… [`retrieval_corpus.csv`](https://github.com/asadsandhu/RAG-Diagnostic-Assistant/blob/main/retrieval_corpus.csv) * โœ… [`faiss_index.bin`](https://github.com/asadsandhu/RAG-Diagnostic-Assistant/blob/main/faiss_index.bin) --- ## ๐Ÿ“ Project Structure ``` RAG-Diagnostic-Assistant/ โ”œโ”€โ”€ app.py โ”œโ”€โ”€ faiss_index.bin โ”œโ”€โ”€ retrieval_corpus.csv โ”œโ”€โ”€ requirements.txt โ”œโ”€โ”€ assets/ โ”‚ โ””โ”€โ”€ demo.png โ””โ”€โ”€ README.md ``` --- ## ๐Ÿ‘ค Author Built with โค๏ธ by [Asad Ali](https://www.linkedin.com/in/asadsandhu0/) * ๐Ÿง  Medium: [@asadsandhu](https://medium.com/@asadsandhu) * ๐Ÿ’ป GitHub: [@asadsandhu](https://github.com/asadsandhu) * ๐Ÿค— Hugging Face: [@asadsandhu](https://huggingface.co/asadsandhu) --- ## ๐Ÿ“œ License MIT License โ€” see [LICENSE](https://opensource.org/license/mit) --- ## ๐Ÿ™ Acknowledgments * MIMIC-IV-Ext-DiReCT โ€“ Annotated diagnostic dataset * Hugging Face Transformers + Gradio * SentenceTransformers + FAISS * BioMistral + NousResearch --- > โš ๏ธ **Disclaimer**: This is a research prototype and not intended for clinical decision-making.