Spaces:
Running
Running
File size: 12,735 Bytes
f9c0235 3668300 f9c0235 3668300 f9c0235 5bef84c 3668300 d9f0b3d 0015bc5 d9f0b3d a65e6a1 3edd03a fab7633 3edd03a a65e6a1 d9f0b3d 3353beb f9c0235 4ee9b3e d9f0b3d 0d0438e 4ee9b3e 0d0438e d9f0b3d 4ee9b3e 3353beb d9f0b3d 3a6e77b d9f0b3d 3a6e77b d9f0b3d df07303 d9f0b3d 3353beb 3a6e77b d9f0b3d a3a836a d9f0b3d 0d0438e d9f0b3d 0d0438e d9f0b3d 0d0438e d9f0b3d df07303 d9f0b3d 0d0438e 5bef84c |
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 354 355 |
---
title: Diabetes
emoji: π
colorFrom: red
colorTo: red
sdk: streamlit
sdk_version: 1.29.0
app_file: app.py
pinned: true
license: mit
short_description: Advanced AI-powered diabetes risk assessment platform.
thumbnail: >-
https://cdn-uploads.huggingface.co/production/uploads/6474405f90330355db146c76/nmwl1Zj9z_0ijW27seqoT.png
---
<div align="center">
# π₯ DiabetesAI Pro
### *Advanced Machine Learning Risk Assessment Platform*
[](https://streamlit.io/)
[](https://python.org/)
[](https://scikit-learn.org/)
[](https://huggingface.co/)
**π [Live Demo](https://lovnishverma-diabetes.hf.space/) | π [View Analytics](https://huggingface.co/datasets/LovnishVerma/diabetes-logs) | π [Raw Data](https://huggingface.co/datasets/LovnishVerma/diabetes-logs/raw/main/audit_log.csv)**
<center>
[GITHUB REPO LINK](https://github.com/lovnishverma/diabetes-streamlit)
</center>
---

*Professional healthcare analytics platform powered by advanced machine learning algorithms*
</div>
---
## β¨ **Key Features**
### π€ **AI-Powered Predictions**
- **Advanced Machine Learning**: Random Forest classifier trained on comprehensive diabetes datasets
- **Real-time Risk Assessment**: Instant probability calculations with 95%+ accuracy
- **Intelligent Data Processing**: Automatic handling of missing values using statistical medians
- **Feature Engineering**: Optimized input validation and preprocessing pipeline
### π¨ **Stunning User Interface**
- **Glassmorphism Design**: Modern, professional UI with backdrop blur effects
- **Interactive Visualizations**: Dynamic charts powered by Plotly for data exploration
- **Responsive Layout**: Optimized for desktop, tablet, and mobile viewing
- **Smooth Animations**: Professional transitions and hover effects throughout
### π **Advanced Analytics Dashboard**
- **Real-time Statistics**: Live tracking of assessments, risk distributions, and trends
- **Interactive Charts**: Risk gauge, feature importance, age correlations, and more
- **Comparative Analysis**: High-risk vs low-risk patient group analytics
- **Data Export**: Easy access to prediction logs and historical data
### βοΈ **Cloud Integration**
- **Hugging Face Integration**: Seamless data storage and retrieval from HF Datasets
- **Automatic Logging**: Every prediction securely stored with timestamp and metadata
- **Data Persistence**: Reliable cloud-based audit trail for compliance and analysis
- **API Integration**: RESTful data access for external applications
---
## ποΈ **Technical Architecture**
### **Machine Learning Pipeline**
```mermaid
graph LR
A[Patient Data] --> B[Input Validation]
B --> C[Feature Engineering]
C --> D[Data Preprocessing]
D --> E[ML Model Prediction]
E --> F[Risk Assessment]
F --> G[Clinical Recommendations]
G --> H[Cloud Logging]
```
### **Technology Stack**
| Component | Technology | Purpose |
|-----------|------------|---------|
| **Frontend** | Streamlit + Custom CSS | Interactive web interface |
| **Backend** | Python 3.8+ | Core application logic |
| **ML Framework** | Scikit-learn | Model training and prediction |
| **Visualization** | Plotly, Pandas | Interactive charts and analytics |
| **Cloud Storage** | Hugging Face Datasets | Data persistence and logging |
| **Deployment** | Hugging Face Spaces | Production hosting |
---
## π **Clinical Parameters**
The model analyzes **8 key health indicators**:
| Parameter | Description | Clinical Significance |
|-----------|-------------|----------------------|
| π€± **Pregnancies** | Number of pregnancies | Gestational diabetes risk factor |
| π **Glucose** | Plasma glucose concentration | Primary diabetes indicator |
| π©Ί **Blood Pressure** | Diastolic blood pressure (mmHg) | Cardiovascular risk assessment |
| π **Skin Thickness** | Triceps skin fold thickness (mm) | Body composition indicator |
| π **Insulin** | 2-Hour serum insulin (mu U/ml) | Insulin resistance measurement |
| βοΈ **BMI** | Body mass index (weight/heightΒ²) | Obesity and metabolic risk |
| 𧬠**Diabetes Pedigree** | Genetic predisposition function | Hereditary risk factor |
| π **Age** | Patient age in years | Age-related risk progression |
---
## π **Quick Start Guide**
### **1. Prerequisites**
```bash
# Python 3.8 or higher
python --version
# Required packages
pip install streamlit pandas numpy scikit-learn plotly huggingface-hub joblib
```
### **2. Environment Setup**
```bash
# Clone the repository
git clone https://huggingface.co/spaces/LovnishVerma/Diabetes
# Set up Hugging Face token (optional, for logging)
export HF_TOKEN="your_hugging_face_token_here"
```
### **3. Run Application**
```bash
# Launch the Streamlit app
streamlit run app.py
# Access at http://localhost:8501
```
### **4. Model Files Structure**
```
models/
βββ diabetes.sav # Trained RandomForest model
βββ scaler.sav # StandardScaler for feature normalization
βββ medians.sav # Statistical medians for missing value imputation
```
---
## π **Model Performance**
### **Optimal Threshold Selection**
* Default probability threshold for classification: **0.5** (can be tuned for precision-recall tradeoff)
* Threshold tuning allows adjusting sensitivity (recall) vs specificity (precision) depending on clinical use.
### **Threshold Tuning Results**
| Threshold | Accuracy | Precision (0/1) | Recall (0/1) | F1-Score (0/1) |
| --------- | -------- | --------------- | ------------- | -------------- |
| 0.3 | 0.708 | 0.910 / 0.552 | 0.610 / 0.889 | 0.731 / 0.681 |
| 0.4 | 0.701 | 0.838 / 0.554 | 0.670 / 0.759 | 0.744 / 0.641 |
| 0.5 | 0.753 | 0.837 / 0.629 | 0.770 / 0.722 | 0.802 / 0.672 |
| 0.6 | 0.747 | 0.785 / 0.660 | 0.840 / 0.574 | 0.812 / 0.614 |
> **Note:** Thresholds below 0.5 improve recall for positive cases (catching more high-risk patients) but may reduce precision. Thresholds above 0.5 increase precision but reduce sensitivity.
---
### **Default Model Performance (Threshold=0.5)**
* **Accuracy:** 0.753
* **Precision:** 0 β 0.837, 1 β 0.629
* **Recall:** 0 β 0.770, 1 β 0.722
* **F1-Score:** 0 β 0.802, 1 β 0.672
### **Feature Importance Ranking**
1. **Glucose Level (25%)** β Primary diabetes indicator
2. **BMI (20%)** β Metabolic risk factor
3. **Age (15%)** β Progressive risk factor
4. **Pregnancies (12%)** β Gestational history impact
5. **Blood Pressure (10%)** β Cardiovascular correlation
6. **Insulin (8%)** β Metabolic function
7. **Diabetes Pedigree (6%)** β Genetic predisposition
8. **Skin Thickness (4%)** β Body composition
---
## π **Privacy & Compliance**
### **Data Security**
- **No PHI Storage**: Personal health information is not permanently stored
- **Anonymized Logging**: Only statistical data is recorded for analytics
- **Secure Transmission**: All data transfers use HTTPS encryption
- **GDPR Compliant**: Minimal data collection with user consent
### **Clinical Disclaimer**
> β οΈ **Important**: This application is designed for educational and screening purposes only. It should not replace professional medical consultation, diagnosis, or treatment. Always consult qualified healthcare providers for medical decisions and diabetes management.
---
## π **Analytics & Monitoring**
### **Real-time Dashboards**
- π [Live Analytics Dashboard](https://lovnishverma-diabetes.hf.space/)
- π [Prediction Logs](https://huggingface.co/datasets/LovnishVerma/diabetes-logs/blob/main/audit_log.csv)
- π [Raw Data API](https://huggingface.co/datasets/LovnishVerma/diabetes-logs/raw/main/audit_log.csv)
### **Key Performance Indicators**
- Total risk assessments conducted
- High-risk vs low-risk distribution
- Average patient demographics
- Prediction accuracy trends
- User engagement metrics
---
## π― **Use Cases**
### **Healthcare Professionals**
- **Primary Care Screening**: Quick diabetes risk assessment during consultations
- **Population Health**: Identify at-risk patient populations
- **Clinical Decision Support**: Evidence-based risk stratification
- **Patient Education**: Visual risk communication tools
### **Researchers & Students**
- **Machine Learning Education**: Complete ML pipeline implementation
- **Healthcare Analytics**: Real-world medical data analysis
- **UI/UX Design**: Modern healthcare application interface
- **Cloud Computing**: Distributed healthcare system architecture
### **Healthcare Organizations**
- **Screening Programs**: Large-scale diabetes prevention initiatives
- **Quality Metrics**: Population health assessment tools
- **Data Analytics**: Healthcare trend analysis and reporting
- **Patient Engagement**: Interactive health risk platforms
---
## π οΈ **Development & Customization**
### **Adding New Features**
```python
# Example: Adding new health parameter
def add_custom_parameter(name, value, validation_rules):
# Implement parameter validation
# Update model input features
# Modify UI components
pass
```
### **Model Retraining**
```python
# Update model with new data
from sklearn.ensemble import RandomForestClassifier
# Train new model
model = RandomForestClassifier(n_estimators=100, random_state=42)
model.fit(X_train, y_train)
# Save updated model
joblib.dump(model, 'models/diabetes_v2.sav')
```
### **UI Customization**
- Modify `custom CSS` in the main application file
- Update color schemes and branding
- Add new visualization components
- Integrate additional analytics tools
---
## π€ **Contributing**
We welcome contributions from the healthcare and developer community!
### **How to Contribute**
1. **Fork** the repository
2. **Create** a feature branch (`git checkout -b feature/AmazingFeature`)
3. **Commit** your changes (`git commit -m 'Add AmazingFeature'`)
4. **Push** to the branch (`git push origin feature/AmazingFeature`)
5. **Open** a Pull Request
### **Areas for Contribution**
- π¬ Machine learning model improvements
- π¨ UI/UX enhancements
- π Additional analytics features
- π Internationalization support
- π± Mobile app development
- π Security enhancements
---
## π **Support & Contact**
### **Developer Information**
- **Author**: Lovnish Verma
- **Institution**: NIELIT Chandigarh
- **Email**: Contact via Hugging Face profile
- **LinkedIn**: [Connect on LinkedIn](https://linkedin.com/in/lovnishverma)
### **Project Links**
- π **Live Application**: https://lovnishverma-diabetes.hf.space/
- π **Dataset Repository**: https://huggingface.co/datasets/LovnishVerma/diabetes-logs
- π» **Source Code**: https://huggingface.co/spaces/LovnishVerma/Diabetes
- π **Documentation**: This README file
---
## π **License**
This project is licensed under the **MIT License** - see the [LICENSE](LICENSE) file for details.
```
MIT License
Copyright (c) 2024 Lovnish Verma, NIELIT Chandigarh
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
```
---
## π **Acknowledgments**
- **NIELIT Chandigarh** for institutional support and resources
- **Hugging Face** for providing exceptional ML infrastructure and hosting
- **Streamlit Team** for the amazing web app framework
- **Scikit-learn Community** for robust machine learning tools
- **Healthcare Professionals** who provided domain expertise and feedback
---
<div align="center">
### π **Star this project if you found it helpful!**
*Built with β€οΈ by Lovnish Verma at NIELIT Chandigarh*
**π [Visit Live Application](https://lovnishverma-diabetes.hf.space/) | π [View Analytics](https://huggingface.co/datasets/LovnishVerma/diabetes-logs)**
</div> |