Spaces:
Sleeping
Sleeping
YanBoChen
commited on
Commit
·
b3ad1ee
1
Parent(s):
2069f6b
Add .gitattributes file, update app.py for Spaces compatibility, and create requirements files
Browse files- .gitattributes +4 -0
- README.md +93 -421
- app.py +8 -3
- united_requirements.txt → requirements.txt +4 -0
- requirements_optimized.txt +43 -0
.gitattributes
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.ann filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
models/**/*.json filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
customization/**/*.json filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
|
@@ -1,449 +1,121 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
- ✅ **UserPromptProcessor** (`src/user_prompt.py`)
|
| 21 |
-
- Level 1: Predefined medical condition mapping (instant response)
|
| 22 |
-
- Level 2: LLM-based condition extraction (Llama3-Med42-70B)
|
| 23 |
-
- Level 3: Semantic search fallback
|
| 24 |
-
- Level 4: Medical query validation (100% non-medical rejection)
|
| 25 |
-
- Level 5: Generic medical search for rare conditions
|
| 26 |
-
|
| 27 |
-
#### **2. Dual-Index Retrieval System**
|
| 28 |
-
|
| 29 |
-
- ✅ **BasicRetrievalSystem** (`src/retrieval.py`)
|
| 30 |
-
- Emergency medical guidelines index (emergency.ann)
|
| 31 |
-
- Treatment protocols index (treatment.ann)
|
| 32 |
-
- Vector-based similarity search using PubMedBERT embeddings
|
| 33 |
-
- Intelligent deduplication and result ranking
|
| 34 |
-
|
| 35 |
-
#### **3. Medical Knowledge Base**
|
| 36 |
-
|
| 37 |
-
- ✅ **MedicalConditions** (`src/medical_conditions.py`)
|
| 38 |
-
- Predefined condition-keyword mappings
|
| 39 |
-
- Medical terminology validation
|
| 40 |
-
- Extensible condition database
|
| 41 |
-
|
| 42 |
-
#### **4. LLM Integration**
|
| 43 |
-
|
| 44 |
-
- ✅ **Med42-70B Client** (`src/llm_clients.py`)
|
| 45 |
-
- Specialized medical language model integration
|
| 46 |
-
- Dual-layer rejection detection for non-medical queries
|
| 47 |
-
- Robust error handling and timeout management
|
| 48 |
-
|
| 49 |
-
#### **5. Medical Advice Generation**
|
| 50 |
-
|
| 51 |
-
- ✅ **MedicalAdviceGenerator** (`src/generation.py`)
|
| 52 |
-
- RAG-based prompt construction
|
| 53 |
-
- Intention-aware chunk selection (treatment/diagnosis)
|
| 54 |
-
- Confidence scoring and response formatting
|
| 55 |
-
- Integration with Med42-70B for clinical advice generation
|
| 56 |
-
|
| 57 |
-
#### **6. Data Processing Pipeline**
|
| 58 |
-
|
| 59 |
-
- ✅ **Processed Medical Guidelines** (`src/data_processing.py`)
|
| 60 |
-
- ~4000 medical guidelines from EPFL-LLM dataset
|
| 61 |
-
- Emergency subset: ~2000-2500 records
|
| 62 |
-
- Treatment subset: ~2000-2500 records
|
| 63 |
-
- PubMedBERT embeddings (768 dimensions)
|
| 64 |
-
- ANNOY vector indices for fast retrieval
|
| 65 |
-
|
| 66 |
-
## 📊 **System Performance (Validated)**
|
| 67 |
-
|
| 68 |
-
### **Comprehensive Evaluation Results (Metrics 1-8)**
|
| 69 |
-
|
| 70 |
-
```
|
| 71 |
-
🎯 Multi-Level Fallback Performance: 5-layer processing pipeline
|
| 72 |
-
- Level 1 (Predefined): Instant response for known conditions
|
| 73 |
-
- Level 2+4 (Combined LLM): 40% time reduction through optimization
|
| 74 |
-
- Level 3 (Semantic Search): High-quality embedding retrieval
|
| 75 |
-
- Level 5 (Generic): 100% fallback coverage
|
| 76 |
-
|
| 77 |
-
📈 RAG vs Direct LLM Comparison (9 test queries):
|
| 78 |
-
- RAG System Actionability: 0.900 vs Direct: 0.789 (14.1% improvement)
|
| 79 |
-
- RAG Evidence Quality: 0.900 vs Direct: 0.689 (30.6% improvement)
|
| 80 |
-
- Category Performance: RAG superior in all categories (Diagnosis, Treatment, Mixed)
|
| 81 |
-
- Complex Queries (Mixed): RAG shows 30%+ advantage over Direct LLM
|
| 82 |
-
```
|
| 83 |
-
|
| 84 |
-
### **Detailed Performance Metrics**
|
| 85 |
-
|
| 86 |
-
```
|
| 87 |
-
🔍 Metric 1 - Latency Analysis:
|
| 88 |
-
- Average Response Time: 15.5s (RAG) vs 8.2s (Direct)
|
| 89 |
-
- Condition Extraction: 2.6s average
|
| 90 |
-
- Retrieval + Generation: 12.9s average
|
| 91 |
-
|
| 92 |
-
📊 Metric 2-4 - Quality Assessment:
|
| 93 |
-
- Extraction Success Rate: 69.2% across fallback levels
|
| 94 |
-
- Retrieval Relevance: 0.245-0.326 (medical domain optimized)
|
| 95 |
-
- Content Coverage: 8-9 guidelines per query with balanced emergency/treatment
|
| 96 |
-
|
| 97 |
-
🎯 Metrics 5-6 - Clinical Quality (LLM Judge Evaluation):
|
| 98 |
-
- Clinical Actionability: RAG (9.0/10) > Direct (7.9/10)
|
| 99 |
-
- Evidence Quality: RAG (9.0/10) > Direct (6.9/10)
|
| 100 |
-
- Treatment Queries: RAG achieves highest scores (9.3/10)
|
| 101 |
-
- All scores exceed clinical thresholds (7.0 actionability, 7.5 evidence)
|
| 102 |
-
|
| 103 |
-
📈 Metrics 7-8 - Precision & Ranking:
|
| 104 |
-
- Precision@5: High relevance in medical guideline retrieval
|
| 105 |
-
- MRR (Mean Reciprocal Rank): Optimized for clinical decision-making
|
| 106 |
-
- Source Diversity: Balanced emergency and treatment protocol coverage
|
| 107 |
-
```
|
| 108 |
-
|
| 109 |
-
## 📈 **EVALUATION SYSTEM**
|
| 110 |
-
|
| 111 |
-
### **Comprehensive Medical AI Evaluation Pipeline**
|
| 112 |
-
|
| 113 |
-
OnCall.ai includes a complete evaluation framework with 8 key metrics to assess system performance across multiple dimensions:
|
| 114 |
-
|
| 115 |
-
#### **🎯 General Pipeline Overview**
|
| 116 |
-
|
| 117 |
-
```
|
| 118 |
-
Query Input → RAG/Direct Processing → Multi-Metric Evaluation → Comparative Analysis
|
| 119 |
-
│ │ │ │
|
| 120 |
-
└─ Test Queries └─ Medical Outputs └─ Automated Metrics └─ Visualization
|
| 121 |
-
(9 scenarios) (JSON format) (Scores & Statistics) (4-panel charts)
|
| 122 |
-
```
|
| 123 |
-
|
| 124 |
-
#### **📊 Metrics 1-8: Detailed Assessment Framework**
|
| 125 |
-
|
| 126 |
-
##### **⚡ Metric 1: Latency Analysis**
|
| 127 |
-
|
| 128 |
-
- **Purpose**: Measure system response time and processing efficiency
|
| 129 |
-
- **Operation**: `python evaluation/latency_evaluator.py`
|
| 130 |
-
- **Key Findings**: RAG averages 15.5s, Direct averages 8.2s
|
| 131 |
-
|
| 132 |
-
##### **🔍 Metric 2-4: Quality Assessment**
|
| 133 |
-
|
| 134 |
-
- **Components**: Extraction success, retrieval relevance, content coverage
|
| 135 |
-
- **Key Findings**: 69.2% extraction success, 0.245-0.326 relevance scores
|
| 136 |
-
|
| 137 |
-
##### **🏥 Metrics 5-6: Clinical Quality (LLM Judge)**
|
| 138 |
-
|
| 139 |
-
- **Purpose**: Professional evaluation of clinical actionability and evidence quality
|
| 140 |
-
- **Operation**: `python evaluation/fixed_judge_evaluator.py rag,direct --batch-size 3`
|
| 141 |
-
- **Charts**: `python evaluation/metric5_6_llm_judge_chart_generator.py`
|
| 142 |
-
- **Key Findings**: RAG (9.0/10) significantly outperforms Direct (7.9/10 actionability, 6.9/10 evidence)
|
| 143 |
-
|
| 144 |
-
##### **🎯 Metrics 7-8: Precision & Ranking**
|
| 145 |
-
|
| 146 |
-
- **Operation**: `python evaluation/metric7_8_precision_MRR.py`
|
| 147 |
-
- **Key Findings**: High precision in medical guideline retrieval
|
| 148 |
-
|
| 149 |
-
#### **🏆 Evaluation Results Summary**
|
| 150 |
-
|
| 151 |
-
- **RAG Advantages**: 30.6% better evidence quality, 14.1% higher actionability
|
| 152 |
-
- **System Reliability**: 100% fallback coverage, clinical threshold compliance
|
| 153 |
-
- **Human Evaluation**: Raw outputs available in `evaluation/results/medical_outputs_*.json`
|
| 154 |
-
|
| 155 |
-
## 🛠️ **Technical Architecture**
|
| 156 |
-
|
| 157 |
-
### **Data Flow**
|
| 158 |
-
|
| 159 |
-
```
|
| 160 |
-
User Query → Level 1: Predefined Mapping
|
| 161 |
-
↓ (if fails)
|
| 162 |
-
Level 2: LLM Extraction
|
| 163 |
-
↓ (if fails)
|
| 164 |
-
Level 3: Semantic Search
|
| 165 |
-
↓ (if fails)
|
| 166 |
-
Level 4: Medical Validation
|
| 167 |
-
↓ (if fails)
|
| 168 |
-
Level 5: Generic Search
|
| 169 |
-
↓ (if fails)
|
| 170 |
-
No Match Found
|
| 171 |
-
```
|
| 172 |
-
|
| 173 |
-
### **Core Technologies**
|
| 174 |
-
|
| 175 |
-
- **Embeddings**: NeuML/pubmedbert-base-embeddings (768D)
|
| 176 |
-
- **Vector Search**: ANNOY indices with angular distance
|
| 177 |
-
- **LLM**: m42-health/Llama3-Med42-70B (medical specialist)
|
| 178 |
-
- **Dataset**: EPFL-LLM medical guidelines (~4000 documents)
|
| 179 |
-
|
| 180 |
-
### **Fallback Mechanism**
|
| 181 |
-
|
| 182 |
-
```
|
| 183 |
-
Level 1: Predefined Mapping (0.001s) → Success: Direct return
|
| 184 |
-
Level 2: LLM Extraction (8-15s) → Success: Condition mapping
|
| 185 |
-
Level 3: Semantic Search (1-2s) → Success: Sliding window chunks
|
| 186 |
-
Level 4: Medical Validation (8-10s) → Fail: Return rejection
|
| 187 |
-
Level 5: Generic Search (1s) → Final: General medical guidance
|
| 188 |
-
```
|
| 189 |
-
|
| 190 |
-
## 🚀 **NEXT PHASE: System Optimization & Enhancement**
|
| 191 |
-
|
| 192 |
-
### **📊 Current Status (2025-08-09)**
|
| 193 |
-
|
| 194 |
-
#### **✅ COMPLETED: Comprehensive Evaluation System**
|
| 195 |
-
|
| 196 |
-
- **Metrics 1-8 Framework**: Complete assessment pipeline implemented
|
| 197 |
-
- **RAG vs Direct Comparison**: Validated RAG system superiority (30%+ better evidence quality)
|
| 198 |
-
- **LLM Judge Evaluation**: Automated clinical quality assessment with 4-panel visualization
|
| 199 |
-
- **Performance Benchmarking**: Quantified system capabilities across all dimensions
|
| 200 |
-
- **Human Evaluation Tools**: Raw output comparison framework available
|
| 201 |
-
|
| 202 |
-
#### **✅ COMPLETED: Production-Ready Pipeline**
|
| 203 |
-
|
| 204 |
-
- **5-Layer Fallback System**: 69.2% success rate with 100% coverage
|
| 205 |
-
- **Dual-Index Retrieval**: Emergency and treatment guidelines optimized
|
| 206 |
-
- **Med42-70B Integration**: Specialized medical LLM with robust error handling
|
| 207 |
-
|
| 208 |
-
### **🎯 Future Goals**
|
| 209 |
-
|
| 210 |
-
#### **🔊 Phase 1: Audio Integration Enhancement**
|
| 211 |
-
|
| 212 |
-
- [ ] **Voice Input Pipeline**
|
| 213 |
-
- [ ] Whisper ASR integration for medical terminology
|
| 214 |
-
- [ ] Audio preprocessing and noise reduction
|
| 215 |
-
- [ ] Medical vocabulary optimization for transcription accuracy
|
| 216 |
-
- [ ] **Voice Output System**
|
| 217 |
-
- [ ] Text-to-Speech (TTS) for medical advice delivery
|
| 218 |
-
- [ ] SSML markup for proper medical pronunciation
|
| 219 |
-
- [ ] Audio response caching for common scenarios
|
| 220 |
-
- [ ] **Multi-Modal Interface**
|
| 221 |
-
- [ ] Simultaneous text + audio input support
|
| 222 |
-
- [ ] Audio quality validation and fallback to text
|
| 223 |
-
- [ ] Mobile-friendly voice interface optimization
|
| 224 |
-
|
| 225 |
-
#### **⚡ Phase 2: System Performance Optimization (5→4 Layer Architecture)**
|
| 226 |
-
|
| 227 |
-
Based on `docs/20250809optimization/5level_to_4layer.md` analysis:
|
| 228 |
-
|
| 229 |
-
- [ ] **Query Cache Implementation** (80% P95 latency reduction expected)
|
| 230 |
-
- [ ] String similarity matching (0.85 threshold)
|
| 231 |
-
- [ ] In-memory LRU cache (1000 query limit)
|
| 232 |
-
- [ ] Cache hit monitoring and optimization
|
| 233 |
-
- [ ] **Layer Reordering Optimization**
|
| 234 |
-
- [ ] L1: Enhanced Predefined Mapping (expand from 12 to 154 keywords)
|
| 235 |
-
- [ ] L2: Semantic Search (moved up for better coverage)
|
| 236 |
-
- [ ] L3: LLM Analysis (combined extraction + validation)
|
| 237 |
-
- [ ] L4: Generic Search (final fallback)
|
| 238 |
-
- [ ] **Performance Targets**:
|
| 239 |
-
- P95 latency: 15s → 3s (80% improvement)
|
| 240 |
-
- L1 success rate: 15% → 30% (2x improvement)
|
| 241 |
-
- Cache hit rate: 0% → 30% (new capability)
|
| 242 |
-
|
| 243 |
-
#### **📱 Phase 3: Interactive Interface Polish**
|
| 244 |
-
|
| 245 |
-
- [ ] **Enhanced Gradio Interface** (`app.py` improvements)
|
| 246 |
-
- [ ] Real-time processing indicators
|
| 247 |
-
- [ ] Audio input/output controls
|
| 248 |
-
- [ ] Advanced debug mode with performance metrics
|
| 249 |
-
- [ ] Mobile-responsive design optimization
|
| 250 |
-
- [ ] **User Experience Enhancements**
|
| 251 |
-
- [ ] Query suggestion system based on common medical scenarios
|
| 252 |
-
- [ ] Progressive disclosure of technical details
|
| 253 |
-
- [ ] Integrated help system with usage examples
|
| 254 |
-
|
| 255 |
-
### **🔮 Further Enhancements (1-2 Months)**
|
| 256 |
-
|
| 257 |
-
#### **📊 Advanced Analytics & Monitoring**
|
| 258 |
-
|
| 259 |
-
- [ ] **Real-time Performance Dashboard**
|
| 260 |
-
- [ ] Layer success rate monitoring
|
| 261 |
-
- [ ] Cache effectiveness analysis
|
| 262 |
-
- [ ] User query pattern insights
|
| 263 |
-
- [ ] **Continuous Evaluation Pipeline**
|
| 264 |
-
- [ ] Automated regression testing
|
| 265 |
-
- [ ] Performance benchmark tracking
|
| 266 |
-
- [ ] Clinical accuracy monitoring with expert review
|
| 267 |
-
|
| 268 |
-
#### **🎯 Medical Specialization Expansion**
|
| 269 |
-
|
| 270 |
-
- [ ] **Specialty-Specific Modules**
|
| 271 |
-
- [ ] Cardiology-focused pipeline
|
| 272 |
-
- [ ] Pediatric emergency protocols
|
| 273 |
-
- [ ] Trauma surgery guidelines integration
|
| 274 |
-
- [ ] **Multi-Language Support**
|
| 275 |
-
- [ ] Spanish medical terminology
|
| 276 |
-
- [ ] French healthcare guidelines
|
| 277 |
-
- [ ] Localized medical protocol adaptation
|
| 278 |
-
|
| 279 |
-
#### **🔬 Research & Development**
|
| 280 |
-
|
| 281 |
-
- [ ] **Advanced RAG Techniques**
|
| 282 |
-
- [ ] Hierarchical retrieval architecture
|
| 283 |
-
- [ ] Dynamic chunk sizing optimization
|
| 284 |
-
- [ ] Cross-reference validation systems
|
| 285 |
-
- [ ] **AI Safety & Reliability**
|
| 286 |
-
- [ ] Uncertainty quantification in medical advice
|
| 287 |
-
- [ ] Adversarial query detection
|
| 288 |
-
- [ ] Bias detection and mitigation in clinical recommendations
|
| 289 |
-
|
| 290 |
-
### **📋 Updated Performance Targets**
|
| 291 |
-
|
| 292 |
-
#### **Post-Optimization Goals**
|
| 293 |
-
|
| 294 |
-
```
|
| 295 |
-
⚡ Latency Improvements:
|
| 296 |
-
- P95 Response Time: <3 seconds (current: 15s)
|
| 297 |
-
- P99 Response Time: <0.5 seconds (current: 25s)
|
| 298 |
-
- Cache Hit Rate: >30% (new metric)
|
| 299 |
-
|
| 300 |
-
🎯 Quality Maintenance:
|
| 301 |
-
- Clinical Actionability: ≥9.0/10 (maintain current RAG performance)
|
| 302 |
-
- Evidence Quality: ≥9.0/10 (maintain current RAG performance)
|
| 303 |
-
- System Reliability: 100% fallback coverage (maintain)
|
| 304 |
-
|
| 305 |
-
🔊 Audio Experience:
|
| 306 |
-
- Voice Recognition Accuracy: >95% for medical terms
|
| 307 |
-
- Audio Response Latency: <2 seconds
|
| 308 |
-
- Multi-modal Success Rate: >90%
|
| 309 |
-
```
|
| 310 |
-
|
| 311 |
-
#### **System Scalability**
|
| 312 |
-
|
| 313 |
-
```
|
| 314 |
-
📈 Capacity Targets:
|
| 315 |
-
- Concurrent Users: 100+ simultaneous queries
|
| 316 |
-
- Query Cache: 10,000+ cached responses
|
| 317 |
-
- Audio Processing: Real-time streaming support
|
| 318 |
|
| 319 |
-
|
| 320 |
-
- HuggingFace Spaces deployment optimization
|
| 321 |
-
- Container orchestration for scaling
|
| 322 |
-
- CDN integration for audio content delivery
|
| 323 |
-
```
|
| 324 |
|
| 325 |
-
|
| 326 |
|
| 327 |
-
|
| 328 |
|
| 329 |
-
|
| 330 |
-
-
|
| 331 |
-
-
|
| 332 |
-
-
|
|
|
|
| 333 |
|
| 334 |
-
|
| 335 |
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
-
|
|
|
|
|
|
|
| 340 |
|
| 341 |
-
|
| 342 |
|
| 343 |
-
|
| 344 |
-
- [ ] System availability: ≥ 99%
|
| 345 |
-
- [ ] Error handling: Graceful degradation
|
| 346 |
-
- [ ] Interface responsiveness: Immediate feedback
|
| 347 |
|
| 348 |
-
|
|
|
|
|
|
|
| 349 |
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
│ ├── retrieval.py # Dual-index vector search
|
| 355 |
-
│ ├── generation.py # RAG-based advice generation
|
| 356 |
-
│ ├── llm_clients.py # Med42-70B integration
|
| 357 |
-
│ ├── medical_conditions.py # Medical knowledge configuration
|
| 358 |
-
│ └── data_processing.py # Dataset preprocessing
|
| 359 |
-
├── models/ # Pre-processed data (✅ Complete)
|
| 360 |
-
│ ├── embeddings/ # Vector embeddings and chunks
|
| 361 |
-
│ └── indices/ # ANNOY vector indices
|
| 362 |
-
├── evaluation/ # Comprehensive evaluation system (✅ Complete)
|
| 363 |
-
│ ├── fixed_judge_evaluator.py # LLM judge evaluation (Metrics 5-6)
|
| 364 |
-
│ ├── latency_evaluator.py # Performance analysis (Metrics 1-4)
|
| 365 |
-
│ ├── metric7_8_precision_MRR.py # Precision/ranking analysis
|
| 366 |
-
│ ├── results/ # Evaluation outputs and comparisons
|
| 367 |
-
│ ├── charts/ # Generated visualization charts
|
| 368 |
-
│ └── queries/test_queries.json # Standard test scenarios
|
| 369 |
-
├── docs/ # Documentation and optimization plans
|
| 370 |
-
│ ├── 20250809optimization/ # System performance optimization
|
| 371 |
-
│ │ └── 5level_to_4layer.md # Layer architecture improvements
|
| 372 |
-
│ └── next/ # Current implementation docs
|
| 373 |
-
├── app.py # ✅ Gradio interface (Complete)
|
| 374 |
-
├── united_requirements.txt # 🔧 Updated: All dependencies
|
| 375 |
-
└── README.md # This file
|
| 376 |
-
```
|
| 377 |
|
| 378 |
-
##
|
| 379 |
|
| 380 |
-
###
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 381 |
|
| 382 |
-
|
| 383 |
-
-
|
| 384 |
-
-
|
| 385 |
-
-
|
| 386 |
|
| 387 |
-
|
| 388 |
|
| 389 |
-
|
| 390 |
-
- **
|
| 391 |
-
- **
|
| 392 |
-
- **
|
| 393 |
-
- **
|
|
|
|
| 394 |
|
| 395 |
-
|
|
|
|
|
|
|
|
|
|
| 396 |
|
| 397 |
-
###
|
|
|
|
|
|
|
|
|
|
| 398 |
|
| 399 |
-
|
| 400 |
-
# Clone repository
|
| 401 |
-
git clone [repository-url]
|
| 402 |
|
| 403 |
-
|
| 404 |
-
python -m venv genAIvenv
|
| 405 |
-
source genAIvenv/bin/activate # On Windows: genAIvenv\Scripts\activate
|
| 406 |
|
| 407 |
-
|
| 408 |
-
|
|
|
|
|
|
|
| 409 |
|
| 410 |
-
|
| 411 |
-
python tests/test_end_to_end_pipeline.py
|
| 412 |
|
| 413 |
-
|
| 414 |
-
python app.py
|
| 415 |
```
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
#
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
#
|
| 424 |
-
|
|
|
|
|
|
|
| 425 |
```
|
| 426 |
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
This system is designed for **research and educational purposes only**. It should not replace professional medical consultation, diagnosis, or treatment. Always consult qualified healthcare providers for medical decisions.
|
| 432 |
-
|
| 433 |
-
### **Current Limitations**
|
| 434 |
-
|
| 435 |
-
- **API Dependencies**: Requires HuggingFace API access for LLM functionality
|
| 436 |
-
- **Dataset Scope**: Currently focused on emergency and treatment guidelines
|
| 437 |
-
- **Language Support**: English medical terminology only
|
| 438 |
-
- **Validation Stage**: System under active development and testing
|
| 439 |
-
|
| 440 |
-
## 📞 **Contact & Support**
|
| 441 |
-
|
| 442 |
-
**Development Team**: OnCall.ai Team
|
| 443 |
-
**Last Updated**: 2025-08-09
|
| 444 |
-
**Version**: 1.0.0 (Evaluation Complete)
|
| 445 |
-
**Status**: 🎯 Ready for Optimization & Audio Enhancement Phase
|
| 446 |
|
| 447 |
---
|
| 448 |
|
| 449 |
-
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: OnCall.ai - Medical Emergency Assistant
|
| 3 |
+
emoji: 🏥
|
| 4 |
+
colorFrom: red
|
| 5 |
+
colorTo: blue
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: "5.38.0"
|
| 8 |
+
app_file: app.py
|
| 9 |
+
python_version: "3.11"
|
| 10 |
+
pinned: false
|
| 11 |
+
license: mit
|
| 12 |
+
tags:
|
| 13 |
+
- medical
|
| 14 |
+
- healthcare
|
| 15 |
+
- RAG
|
| 16 |
+
- emergency
|
| 17 |
+
- clinical-guidance
|
| 18 |
+
- gradio
|
| 19 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
# 🏥 OnCall.ai - Medical Emergency Assistant
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
A RAG-based medical assistant system that provides **evidence-based clinical guidance** for emergency medical situations using real medical guidelines and advanced language models.
|
| 24 |
|
| 25 |
+
## 🎯 What This App Does
|
| 26 |
|
| 27 |
+
OnCall.ai helps healthcare professionals by:
|
| 28 |
+
- **Processing medical queries** through multi-level validation system
|
| 29 |
+
- **Retrieving relevant medical guidelines** from curated emergency medicine datasets
|
| 30 |
+
- **Generating evidence-based clinical advice** using specialized medical LLMs (Llama3-Med42-70B)
|
| 31 |
+
- **Providing transparent, traceable medical guidance** with source attribution
|
| 32 |
|
| 33 |
+
## 🚀 How to Use
|
| 34 |
|
| 35 |
+
1. **Enter your medical query** in the text box (e.g., "Patient with chest pain and shortness of breath")
|
| 36 |
+
2. **Click Submit** to process your query through our RAG pipeline
|
| 37 |
+
3. **Review the response** which includes:
|
| 38 |
+
- Clinical guidance based on medical guidelines
|
| 39 |
+
- Evidence sources and reasoning
|
| 40 |
+
- Confidence level and validation status
|
| 41 |
|
| 42 |
+
## ⚙️ Configuration
|
| 43 |
|
| 44 |
+
This app requires a **HuggingFace token** for accessing the medical language models.
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
### Environment Variables
|
| 47 |
+
- `HF_TOKEN`: Your HuggingFace API token (required for LLM access)
|
| 48 |
+
- `ONCALL_DEBUG`: Set to 'true' to enable debug mode (optional)
|
| 49 |
|
| 50 |
+
### To set up your HuggingFace token:
|
| 51 |
+
1. Get your token from [HuggingFace Settings](https://huggingface.co/settings/tokens)
|
| 52 |
+
2. In this Space, go to **Settings** → **Variables and Secrets**
|
| 53 |
+
3. Add `HF_TOKEN` with your token value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
+
## 🏗️ System Architecture
|
| 56 |
|
| 57 |
+
### Multi-Level Query Processing Pipeline
|
| 58 |
+
1. **Level 1**: Predefined medical condition mapping (instant response)
|
| 59 |
+
2. **Level 2**: LLM-based condition extraction (Llama3-Med42-70B)
|
| 60 |
+
3. **Level 3**: Semantic search fallback
|
| 61 |
+
4. **Level 4**: Medical query validation (100% non-medical rejection)
|
| 62 |
+
5. **Level 5**: Generic medical search for rare conditions
|
| 63 |
|
| 64 |
+
### Dual-Index Retrieval System
|
| 65 |
+
- **Emergency Guidelines Index**: Fast retrieval for critical conditions
|
| 66 |
+
- **Treatment Protocols Index**: Comprehensive clinical procedures
|
| 67 |
+
- **Semantic Search**: Vector-based similarity matching using sentence transformers
|
| 68 |
|
| 69 |
+
## 📋 Technical Details
|
| 70 |
|
| 71 |
+
### Key Features
|
| 72 |
+
- **Complete RAG Pipeline**: Query → Condition Extraction → Retrieval → Generation
|
| 73 |
+
- **Multi-level fallback validation** for robust query processing
|
| 74 |
+
- **Evidence-based medical advice** with transparent source attribution
|
| 75 |
+
- **Gradio interface** for easy interaction
|
| 76 |
+
- **Environment-controlled debug mode** for development
|
| 77 |
|
| 78 |
+
### Models Used
|
| 79 |
+
- **Medical LLM**: Llama3-Med42-70B (specialized medical reasoning)
|
| 80 |
+
- **Embedding Model**: Sentence Transformers for semantic search
|
| 81 |
+
- **Retrieval**: Annoy index for fast approximate nearest neighbor search
|
| 82 |
|
| 83 |
+
### Dataset
|
| 84 |
+
- Curated medical guidelines and emergency protocols
|
| 85 |
+
- Treatment procedures and clinical decision trees
|
| 86 |
+
- Evidence-based medical knowledge base
|
| 87 |
|
| 88 |
+
## ⚠️ Important Disclaimers
|
|
|
|
|
|
|
| 89 |
|
| 90 |
+
🚨 **This tool is for educational and research purposes only.**
|
|
|
|
|
|
|
| 91 |
|
| 92 |
+
- **Not a substitute for professional medical advice**
|
| 93 |
+
- **Not for use in actual medical emergencies**
|
| 94 |
+
- **Always consult qualified healthcare professionals**
|
| 95 |
+
- **Verify all information with authoritative medical sources**
|
| 96 |
|
| 97 |
+
## 🔧 Development Information
|
|
|
|
| 98 |
|
| 99 |
+
### Project Structure
|
|
|
|
| 100 |
```
|
| 101 |
+
├── app.py # Main Gradio application
|
| 102 |
+
├── src/ # Core modules
|
| 103 |
+
│ ├── user_prompt.py # Query processing
|
| 104 |
+
│ ├── retrieval.py # RAG retrieval system
|
| 105 |
+
│ ├── generation.py # Medical advice generation
|
| 106 |
+
│ ├── llm_clients.py # LLM interface
|
| 107 |
+
│ └── medical_conditions.py # Condition mapping
|
| 108 |
+
├── models/ # Pre-trained models and indices
|
| 109 |
+
│ ├── embeddings/ # Vector embeddings
|
| 110 |
+
│ └── indices/ # Search indices
|
| 111 |
+
└── requirements.txt # Dependencies
|
| 112 |
```
|
| 113 |
|
| 114 |
+
### Version
|
| 115 |
+
- **Current Version**: 0.9.0
|
| 116 |
+
- **Last Updated**: 2025-07-31
|
| 117 |
+
- **Author**: OnCall.ai Team
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
---
|
| 120 |
|
| 121 |
+
**🔗 For technical details, issues, or contributions, please refer to the project documentation.**
|
app.py
CHANGED
|
@@ -714,15 +714,20 @@ def main():
|
|
| 714 |
# Create interface
|
| 715 |
interface = create_oncall_interface()
|
| 716 |
|
| 717 |
-
# Launch configuration
|
| 718 |
launch_config = {
|
| 719 |
-
"server_name": "0.0.0.0", # Allow external connections
|
| 720 |
-
"server_port": 7860, # Standard Gradio port
|
| 721 |
"share": False, # Set to True for public links
|
| 722 |
"debug": DEBUG_MODE,
|
| 723 |
"show_error": DEBUG_MODE
|
| 724 |
}
|
| 725 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 726 |
print("🚀 Launching OnCall.ai interface...")
|
| 727 |
print(f"🌐 Interface will be available at: http://localhost:7860")
|
| 728 |
|
|
|
|
| 714 |
# Create interface
|
| 715 |
interface = create_oncall_interface()
|
| 716 |
|
| 717 |
+
# Launch configuration (Spaces-compatible)
|
| 718 |
launch_config = {
|
|
|
|
|
|
|
| 719 |
"share": False, # Set to True for public links
|
| 720 |
"debug": DEBUG_MODE,
|
| 721 |
"show_error": DEBUG_MODE
|
| 722 |
}
|
| 723 |
|
| 724 |
+
# Only set server config for local development
|
| 725 |
+
if not os.getenv('SPACE_ID'): # Not running in Hugging Face Spaces
|
| 726 |
+
launch_config.update({
|
| 727 |
+
"server_name": "0.0.0.0", # Allow external connections
|
| 728 |
+
"server_port": 7860, # Standard Gradio port
|
| 729 |
+
})
|
| 730 |
+
|
| 731 |
print("🚀 Launching OnCall.ai interface...")
|
| 732 |
print(f"🌐 Interface will be available at: http://localhost:7860")
|
| 733 |
|
united_requirements.txt → requirements.txt
RENAMED
|
@@ -1,3 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
accelerate==1.9.0
|
| 2 |
aiofiles==24.1.0
|
| 3 |
aiohappyeyeballs==2.6.1
|
|
|
|
| 1 |
+
# OnCall.ai Medical Emergency Assistant - Dependencies
|
| 2 |
+
# Requires Python 3.11+ for optimal performance and compatibility
|
| 3 |
+
# Developed and tested on Python 3.11.9
|
| 4 |
+
|
| 5 |
accelerate==1.9.0
|
| 6 |
aiofiles==24.1.0
|
| 7 |
aiohappyeyeballs==2.6.1
|
requirements_optimized.txt
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# OnCall.ai Medical Emergency Assistant - Optimized Dependencies
|
| 2 |
+
# Requires Python 3.11+ for optimal performance and compatibility
|
| 3 |
+
# Version ranges locked to prevent breaking changes during deployment
|
| 4 |
+
|
| 5 |
+
# Core ML and AI dependencies - locked to major versions
|
| 6 |
+
gradio>=5.38,<6.0
|
| 7 |
+
huggingface-hub>=0.33,<0.35
|
| 8 |
+
transformers>=4.53,<4.55
|
| 9 |
+
torch>=2.7,<2.8
|
| 10 |
+
sentence-transformers>=3.0,<3.1
|
| 11 |
+
|
| 12 |
+
# Retrieval and indexing
|
| 13 |
+
annoy>=1.17,<1.18
|
| 14 |
+
datasets>=4.0,<4.1
|
| 15 |
+
|
| 16 |
+
# Web server and API
|
| 17 |
+
fastapi>=0.116,<0.117
|
| 18 |
+
uvicorn>=0.35,<0.36
|
| 19 |
+
|
| 20 |
+
# Data processing
|
| 21 |
+
pandas>=2.2,<2.3
|
| 22 |
+
numpy>=2.2,<2.3
|
| 23 |
+
scikit-learn>=1.7,<1.8
|
| 24 |
+
|
| 25 |
+
# File processing
|
| 26 |
+
pypdf>=5.8,<6.0
|
| 27 |
+
python-dotenv>=1.1,<1.2
|
| 28 |
+
|
| 29 |
+
# Image processing (for EasyOCR)
|
| 30 |
+
opencv-python-headless>=4.12,<5.0
|
| 31 |
+
easyocr>=1.7,<1.8
|
| 32 |
+
pillow>=11.0,<12.0
|
| 33 |
+
|
| 34 |
+
# Utilities
|
| 35 |
+
requests>=2.32,<2.33
|
| 36 |
+
tqdm>=4.67,<4.68
|
| 37 |
+
pydantic>=2.11,<2.12
|
| 38 |
+
packaging>=25.0,<26.0
|
| 39 |
+
|
| 40 |
+
# Additional dependencies for your specific features
|
| 41 |
+
llama-index-core>=0.12.50,<0.13
|
| 42 |
+
llama-index-embeddings-huggingface>=0.5,<0.6
|
| 43 |
+
llama-index-llms-huggingface>=0.5,<0.6
|