Spaces:
Sleeping
Sleeping
File size: 4,452 Bytes
18bfaa1 56259e5 18bfaa1 56259e5 18bfaa1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | ---
title: MediBot
emoji: 🩺
colorFrom: yellow
colorTo: blue
sdk: gradio
sdk_version: 6.6.0
python_version: 3.12
app_file: app.py
pinned: false
license: mit
short_description: Medical symptom exploration tool
---
<p align="center">
<img src="static/Medibot%20logo.png" width="320" alt="MediBot Logo">
</p>
<h1 align="center">MediBot</h1>
<p align="center">
Educational symptom exploration with Gradio, OpenAI, FAISS, and a lightweight ranking pipeline.
</p>
<p align="center">
<em>Not a medical device. For educational use only. Do not use this app to rule out emergencies or replace a licensed clinician.</em>
</p>
## Overview
MediBot accepts symptom questions in plain language and can:
- extract structured symptom context from user text
- ask follow-up questions when the symptom signal is too weak or ambiguous
- estimate urgency for recognized symptoms
- rank possible conditions for educational review
- explain named conditions and list precautions
- add travel-aware handling for rare tropical diseases
The app is built around a small multi-step workflow in [app.py](app.py):
- `ReActRouter` builds a short plan for each turn
- `ClarificationAgent` decides whether follow-up questions are needed
- `SymptomSeverityAgent` scores urgency and handles red-flag escalation
- `DiseaseDiagnosisAgent` maps symptoms, retrieves FAISS candidates, and scores them
- description and precaution agents answer disease-specific questions
## Repository Layout
```text
MediBot/
|-- app.py
|-- data/
|-- diagnosis_engine/
|-- eval/
|-- scripts/
|-- static/
|-- tests/
`-- requirements.txt
```
Key directories:
- `data/`: CSV datasets used by the app
- `diagnosis_engine/`: FAISS retrieval, scoring, reranking, prevalence priors, and vocabulary mapping
- `eval/`: deterministic real-query evaluation cases and runner
- `scripts/`: lightweight local checks such as `smoke_check.py`
- `tests/`: pytest coverage for helpers, chat flow, and realistic symptom queries
## Local Setup
1. Create and activate a virtual environment.
2. Install runtime dependencies from `requirements.txt`.
3. Install `requirements-dev.txt` as well if you want to run tests locally.
4. Set `OPENAI_API_KEY` in your environment or a local `.env` file.
5. Run the smoke check before launching the app.
Example:
```bash
python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txt
pip install -r requirements-dev.txt
python scripts/smoke_check.py
python app.py
```
If you use `make`, the repo also includes `MakeFile.mak` with helper targets for setup, tests, and deployment checks.
## Testing
Quick checks:
```bash
python scripts/smoke_check.py
python scripts/evaluate_real_queries.py
```
Pytest:
```bash
.venv\Scripts\python.exe -m pytest tests -q
```
Make targets:
```bash
make -f MakeFile.mak smoke-check
make -f MakeFile.mak eval
make -f MakeFile.mak test
make -f MakeFile.mak deploy-check
```
The real-query evaluation uses natural-language prompts from `eval/real_symptom_queries.json` and runs them through a deterministic fallback path so results stay stable across test runs.
## Hugging Face Deployment
Before deploying to Hugging Face Spaces:
- set `OPENAI_API_KEY` as a Space Secret
- run `python scripts/smoke_check.py`
- optionally run `python scripts/evaluate_real_queries.py`
- confirm all required CSV files are present in `data/`
- review logging behavior and avoid storing raw public symptom text
Do not commit or deploy local-only files:
- `.env`
- `.env.*`
- `logs/`
- `faiss_store/`
- `__pycache__/`
- `*.pyc`
These exclusions are also tracked in `.hfignore`.
Optional to exclude from Spaces if you do not need them there:
- `tests/`
- `eval/`
## Notes on Ranking
The displayed "match strength" is the candidate `hybrid_score`. It combines:
- Jaccard overlap
- TF-IDF cosine similarity
- symptom coverage
- a rarity penalty derived from `diagnosis_engine/prevalence.py`
Weak matches are expected for broad symptom sets. The app explicitly warns users when the top score is low and asks follow-up questions when evidence is too ambiguous.
## Related Docs
- [MediBot_Colab.ipynb](MediBot_Colab.ipynb)
- [APP_FLOW.md](APP_FLOW.md)
- [DEPLOYMENT.md](DEPLOYMENT.md)
- [TRAVEL_PROMPT_FEATURE.md](TRAVEL_PROMPT_FEATURE.md)
- [TROPICAL_DISEASE_FIX.md](TROPICAL_DISEASE_FIX.md)
- [RARE_DISEASE_FIX.md](RARE_DISEASE_FIX.md)
- [RARITY_SIMILARITY_FIX.md](RARITY_SIMILARITY_FIX.md)
- [CONTRIBUTING.md](CONTRIBUTING.md)
|