File size: 13,824 Bytes
f70890a
60e17c6
 
 
 
f70890a
60e17c6
f70890a
 
ebbdb50
60e17c6
f70890a
 
60e17c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
---
title: BioGPT Medical Assistant
emoji: πŸ₯
colorFrom: blue
colorTo: green
sdk: gradio
sdk_version: 4.44.0
app_file: app.py
pinned: false
license: mit
hardware: cpu-basic
---

# πŸ₯ BioGPT Medical Assistant

<div align="center">

![BioGPT](https://img.shields.io/badge/Model-BioGPT--Large-blue)
![Gradio](https://img.shields.io/badge/Interface-Gradio-orange)
![License](https://img.shields.io/badge/License-MIT-green)
![Status](https://img.shields.io/badge/Status-Active-brightgreen)

**Professional AI Medical Chatbot powered by BioGPT-Large**

*Specialized in Pediatric Healthcare Information*

[πŸš€ **Try the App**](https://huggingface.co/spaces) | [πŸ“š **Documentation**](#usage) | [⚠️ **Disclaimer**](#medical-disclaimer)

</div>

---

## 🌟 Features

- πŸ€– **Advanced AI Model**: Powered by Microsoft's BioGPT-Large, trained on biomedical literature
- πŸ‘Ά **Pediatric Focus**: Specialized in children's health and medical conditions
- πŸ” **Intelligent Search**: FAISS vector database for precise medical information retrieval
- πŸ’‘ **Evidence-Based**: Responses grounded in uploaded medical literature
- πŸ–₯️ **GPU Optimized**: 8-bit quantization for efficient inference
- πŸ“± **Mobile Friendly**: Responsive design works on all devices
- πŸ”’ **Privacy Focused**: No permanent storage of uploaded medical data

## πŸš€ Quick Start

### 1. Upload Medical Data
- Click **"Upload Medical Text File"** 
- Select your `.txt` medical literature file (up to 50MB)
- Wait for processing confirmation βœ…

### 2. Start Consulting
- Type your medical question in the chat box
- Get evidence-based responses from BioGPT
- Continue the conversation naturally

### 3. Example Questions
```
πŸ’­ "What causes fever in children?"
πŸ’­ "How should I treat my child's persistent cough?"
πŸ’­ "When should I be concerned about my baby's breathing?"
πŸ’­ "What are the signs of dehydration in infants?"
πŸ’­ "How to manage pediatric allergic reactions?"
```

## 🎯 Use Cases

| Scenario | Example Query | Response Type |
|----------|---------------|---------------|
| **Symptom Assessment** | "My 3-year-old has a rash and fever" | Diagnostic guidance & urgency level |
| **Treatment Information** | "How to treat bronchiolitis in infants?" | Evidence-based treatment options |
| **Prevention Advice** | "How to prevent ear infections in children?" | Preventive measures & recommendations |
| **Emergency Guidance** | "When should I take my child to the ER?" | Clear emergency indicators |
| **Development Concerns** | "Is my baby's breathing pattern normal?" | Developmental milestones & red flags |

## πŸ› οΈ Technical Architecture

```mermaid
graph TD
    A[User Upload] --> B[Text Processing]
    B --> C[Medical Chunking]
    C --> D[Embedding Generation]
    D --> E[FAISS Vector Store]
    
    F[User Query] --> G[Query Embedding]
    G --> H[Vector Similarity Search]
    H --> I[Context Retrieval]
    I --> J[BioGPT Generation]
    J --> K[Medical Response]
    
    L[BioGPT-Large] --> J
    M[8-bit Quantization] --> L
    N[GPU/CPU Auto-detect] --> M
```

### Core Components
- **BioGPT-Large**: Microsoft's medical language model (1.5B parameters)
- **Sentence Transformers**: Medical text embeddings (384 dimensions)
- **FAISS**: High-performance vector similarity search
- **Gradio**: Interactive web interface
- **PyTorch**: Deep learning framework with CUDA support

## πŸ“Š Model Performance

| Metric | Value | Description |
|--------|-------|-------------|
| **Model Size** | 1.5B parameters | Large-scale biomedical language model |
| **Quantization** | 8-bit | Memory-efficient inference |
| **Context Window** | 1024 tokens | Maximum input length |
| **Response Length** | 150 tokens | Focused medical answers |
| **Embedding Dimension** | 384 | Vector search precision |
| **Search Results** | Top 3 chunks | Relevant context retrieval |
| **Hardware** | CPU Basic | Free tier with 2 vCPU, 16GB RAM |

## πŸ’Ύ Supported File Formats

- **Text Files** (`.txt`): Plain text medical literature
- **Encoding**: UTF-8 recommended
- **Size Limit**: Up to 50MB (Hugging Face Spaces limit)
- **Content**: Medical textbooks, research papers, clinical guidelines

### Optimal File Structure
```
PEDIATRIC FEVER MANAGEMENT

SYMPTOMS:
- Temperature above 38Β°C (100.4Β°F)
- Irritability and fussiness
- Poor feeding or appetite loss

TREATMENT:
- Acetaminophen for children over 3 months
- Ibuprofen for children over 6 months
- Ensure adequate hydration

WHEN TO SEEK CARE:
- Fever in infants under 3 months
- Temperature above 40Β°C (104Β°F)
- Signs of dehydration
```

## βš™οΈ System Configuration

The app automatically optimizes based on available hardware:

| Setting | CPU Basic (Free) | With GPU Upgrade |
|---------|------------------|------------------|
| **Model Loading** | 16-bit precision | 8-bit quantization |
| **Device** | CPU | CUDA |
| **Inference Speed** | ~10-15 seconds | ~2-3 seconds |
| **Memory Usage** | ~8GB RAM | ~6GB VRAM |
| **Concurrent Users** | 2-3 users | 5-10 users |

## πŸ§ͺ Example Interactions

<details>
<summary><b>Click to see sample conversations</b></summary>

**User**: "My 2-year-old has been coughing for 3 days. Should I be worried?"

**BioGPT**: "🩺 **Medical Information:** A cough lasting 3 days in a 2-year-old can have several causes, including viral upper respiratory infections, which are common in young children. Monitor for additional symptoms such as fever, difficulty breathing, or changes in appetite. If the cough is accompanied by high fever (>39°C), rapid breathing, or the child appears unusually lethargic, medical evaluation is recommended.

⚠️ **Important:** This information is for educational purposes only. Always consult with qualified healthcare professionals for medical diagnosis, treatment, and personalized advice."

---

**User**: "What are the warning signs of dehydration in babies?"

**BioGPT**: "🩺 **Medical Information:** Warning signs of dehydration in infants include decreased wet diapers (fewer than 6 per day), dry mouth and tongue, sunken fontanelle (soft spot), lethargy or excessive fussiness, and skin that remains "tented" when gently pinched. Severe dehydration may present with sunken eyes, rapid heartbeat, and decreased responsiveness, requiring immediate medical attention.

⚠️ **Important:** This information is for educational purposes only. Always consult with qualified healthcare professionals for medical diagnosis, treatment, and personalized advice."

---

**User**: "Hello!"

**BioGPT**: "πŸ‘‹ Hello! I'm BioGPT, your medical AI assistant specialized in pediatric medicine. Please upload your medical data file first, then ask me any health-related questions!"

</details>

## πŸ“š Usage Guidelines

### βœ… Appropriate Uses
- Educational medical information and research
- Understanding pediatric symptoms and conditions
- Learning about evidence-based treatment options
- Knowing when to seek professional medical care
- Medical training and academic purposes
- Parent education and awareness

### ❌ Inappropriate Uses
- Emergency medical situations (call 911/999/112)
- Replacing professional medical consultation
- Self-diagnosis or self-treatment decisions
- Medication dosing or prescription guidance
- Legal or insurance medical claims
- Critical care decision making

## πŸ” How It Works

1. **Document Processing**: Medical literature is intelligently chunked into semantically meaningful segments (~400 words each)
2. **Embedding Generation**: Each chunk is converted to 384-dimensional vectors using medical-optimized sentence transformers
3. **Vector Storage**: FAISS index enables millisecond similarity search across thousands of medical concepts
4. **Query Processing**: User questions are embedded and matched against the knowledge base using cosine similarity
5. **Context Retrieval**: Top 3 most relevant medical passages are extracted and ranked
6. **Response Generation**: BioGPT-Large synthesizes evidence-based answers from retrieved context with medical reasoning
7. **Safety Filtering**: All responses include appropriate medical disclaimers and professional consultation guidance

## πŸš€ Deployment Information

This application is deployed on Hugging Face Spaces with the following configuration:

- **Platform**: Hugging Face Spaces
- **Hardware**: CPU Basic (2 vCPU, 16GB RAM) - FREE
- **Framework**: Gradio 4.44.0
- **Python**: 3.9+
- **Automatic Scaling**: Handled by Hugging Face infrastructure
- **Uptime**: 99.9% availability
- **Global CDN**: Fast loading worldwide
- **GPU Upgrade**: Available for faster inference (T4 Small: $0.60/hour)

## πŸ”§ For Developers

### Local Development
```bash
# Clone this space
git clone https://huggingface.co/spaces/your-username/biogpt-medical-assistant
cd biogpt-medical-assistant

# Install dependencies
pip install -r requirements.txt

# Run locally
python app.py
```

### File Structure
```
biogpt-medical-assistant/
β”œβ”€β”€ app.py                    # Main Gradio application
β”œβ”€β”€ requirements.txt          # Python dependencies
└── README.md                # This documentation
```

### Key Dependencies
- `torch>=1.12.0` - PyTorch deep learning framework
- `transformers>=4.21.0` - Hugging Face transformers library
- `gradio>=4.0.0` - Web interface framework
- `sentence-transformers` - Text embedding models
- `faiss-cpu` - Vector similarity search
- `bitsandbytes` - 8-bit model quantization

## πŸ“ˆ Performance Monitoring

The application includes built-in performance tracking:

- **Response Time**: Average 10-15 seconds on CPU (2-3 seconds with GPU upgrade)
- **Context Retrieval**: Sub-second vector search
- **Memory Usage**: Optimized for 16GB RAM limit
- **Error Handling**: Graceful fallbacks and user feedback
- **Conversation History**: Session-based chat memory
- **CPU Optimization**: Automatic detection and CPU-optimized inference

## πŸ›‘οΈ Privacy & Security

- **No Data Storage**: Uploaded files are processed in memory only
- **Session Isolation**: Each user session is independent
- **No Logging**: Personal medical queries are not logged
- **HTTPS Encryption**: All communications are encrypted
- **EU GDPR Compliant**: No personal data retention
- **Medical Privacy**: Designed with HIPAA principles in mind

## 🀝 Community & Support

- **Discussions**: Use the Community tab above for questions and feedback
- **Issues**: Report bugs or request features in discussions
- **Medical Accuracy**: Healthcare professionals welcome to provide feedback
- **Updates**: Application is regularly updated with improvements

## πŸ“„ License & Attribution

This project is licensed under the MIT License.

### Model Attributions
- **BioGPT-Large**: Microsoft Research - [Paper](https://arxiv.org/abs/2210.10341)
- **Sentence Transformers**: UKP Lab - [Repository](https://github.com/UKPLab/sentence-transformers)
- **FAISS**: Facebook AI Research - [Repository](https://github.com/facebookresearch/faiss)

### Special Thanks
- **Hugging Face** for providing the infrastructure and hosting platform
- **Medical Community** for the knowledge that powers this assistant
- **Open Source Contributors** for the foundational libraries and tools

---

## ⚠️ Medical Disclaimer

**IMPORTANT MEDICAL DISCLAIMER**

This AI assistant is designed for **educational and informational purposes only**. It is not intended to be a substitute for professional medical advice, diagnosis, or treatment.

### 🚨 Emergency Situations
**Call emergency services immediately (911/999/112) if experiencing:**
- Difficulty breathing or shortness of breath
- Chest pain or pressure  
- Severe bleeding or trauma
- Loss of consciousness or altered mental state
- Severe allergic reactions (anaphylaxis)
- Signs of stroke or heart attack
- Any life-threatening emergency

### 🩺 Professional Medical Care
**Always consult qualified healthcare professionals for:**
- Medical diagnosis and treatment decisions
- Medication prescriptions and dosing instructions
- Serious, persistent, or worsening symptoms
- Chronic condition management and monitoring
- Preventive care, screenings, and vaccinations
- Any concerns about your or your child's health

### πŸ‘Ά Pediatric Emergency Signs
**Seek immediate pediatric medical attention for:**
- Infants under 3 months with any fever (>38Β°C/100.4Β°F)
- Difficulty breathing, wheezing, or rapid breathing in children
- Signs of severe dehydration (sunken fontanelle, no wet diapers)
- Unusual lethargy, excessive fussiness, or unresponsiveness
- Severe vomiting or inability to keep fluids down
- Any concerning changes in your child's behavior or condition

### πŸ“š Information Accuracy
- Responses are based on the medical literature you upload and BioGPT's training data
- Information accuracy depends on the quality and currency of source materials
- Medical knowledge evolves rapidly - always verify with current medical sources
- This AI cannot replace clinical examination, laboratory tests, or imaging studies

### πŸ₯ Limitations
- Cannot provide personalized medical advice for specific individuals
- Cannot interpret medical tests, lab results, or imaging studies
- Cannot prescribe medications or provide dosing instructions
- Cannot diagnose medical conditions or recommend specific treatments
- Should not be used for urgent or emergency medical situations

**By using this application, you acknowledge that you understand these limitations and will not rely solely on this AI assistant for medical decisions. Always prioritize professional medical care for health concerns.**

---

<div align="center">

**πŸ₯ Your Health, Our Priority - But Always Consult the Professionals πŸ₯**

*Empowering Health Education Through AI Technology*

**Made with ❀️ for the medical community and caring parents worldwide**

</div>