Spaces:
Running
A newer version of the Streamlit SDK is available:
1.49.1
title: Diabetes
emoji: π
colorFrom: red
colorTo: red
sdk: streamlit
sdk_version: 1.29.0
app_file: app.py
pinned: false
license: mit
short_description: Advanced AI-powered diabetes risk assessment platform.
π₯ DiabetesAI Pro
Advanced Machine Learning Risk Assessment Platform
π Live Demo | π View Analytics | π Raw Data
Professional healthcare analytics platform powered by advanced machine learning algorithms
β¨ 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
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
# Python 3.8 or higher
python --version
# Required packages
pip install streamlit pandas numpy scikit-learn plotly huggingface-hub joblib
2. Environment Setup
# 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
# 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
- Glucose Level (25%) β Primary diabetes indicator
- BMI (20%) β Metabolic risk factor
- Age (15%) β Progressive risk factor
- Pregnancies (12%) β Gestational history impact
- Blood Pressure (10%) β Cardiovascular correlation
- Insulin (8%) β Metabolic function
- Diabetes Pedigree (6%) β Genetic predisposition
- 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
- π Prediction Logs
- π Raw Data API
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
# 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
# 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
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - 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
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 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
π Star this project if you found it helpful!
Built with β€οΈ by Lovnish Verma at NIELIT Chandigarh
π Visit Live Application | π View Analytics