Spaces:
Running
Running
metadata
title: Diabetes Health Predictor
emoji: π©Ί
colorFrom: blue
colorTo: green
sdk: docker
pinned: false
license: mit
π₯ AI-Powered Diabetes Risk Predictor
Enterprise-Grade Healthcare ML Application - Predict diabetes risk with 95%+ accuracy using advanced machine learning and AI-powered insights.
π Live Demo
HuggingFace: https://naveen-2007-diabetes.hf.space
β¨ Key Features
- π― ML Prediction Engine - XGBoost model with 95%+ accuracy
- π€ AI Health Reports - LLM-powered personalized insights
- π¬ Smart Chatbot - RAG-powered with persistent memory
- π File Upload - Analyze medical reports (PDF/images)
- π Interactive Dashboard - Modern React frontend
- π PDF Reports - Professional medical reports with charts
- π Secure Auth - Firebase Authentication (Email + Google OAuth)
- π± Responsive Design - Works on all devices
- β‘ Optimized Performance - Lazy loading for <30s startup
ποΈ Architecture
React Frontend (TypeScript + Tailwind)
β
Flask Backend (Python 3.11 + Gunicorn)
β
βββββββ΄ββββββ¬βββββββββββ¬βββββββββββ
XGBoost ML Groq LLM Firebase Azure
Model API Database App Svc
π Quick Start
Local Development
# 1. Clone repository
git clone https://github.com/Naveenkumar-2007/Daibetes.git
cd Daibetes
# 2. Install Python dependencies
pip install -r requirements.txt
# 3. Configure environment
cp .env.example .env
# Edit .env with your API keys
# 4. Run backend
python flask_app.py
# App: http://localhost:8000
# 5. Run frontend (separate terminal)
cd frontend
npm install
npm run dev
# React: http://localhost:5173
Environment Variables
Create .env file with:
GROQ_API_KEY=your_groq_api_key
PINECONE_API_KEY=your_pinecone_key
FIREBASE_PROJECT_ID=your_project_id
FIREBASE_API_KEY=your_api_key
SECRET_KEY=your_secret_key
# ... see .env.example for all variables
π¦ Deployment (Azure)
Automatic Deployment
Push to main branch β GitHub Actions deploys automatically
git add .
git commit -m "Your changes"
git push origin main
Required GitHub Secrets
Configure these in GitHub repository settings:
Azure:
AZURE_CREDENTIALS- Service principal JSON
APIs:
GROQ_API_KEY- Groq LLMPINECONE_API_KEY- Vector DB
Firebase (10 secrets):
FIREBASE_API_KEYFIREBASE_PROJECT_IDFIREBASE_PRIVATE_KEY_IDFIREBASE_CLIENT_EMAILFIREBASE_CLIENT_IDFIREBASE_AUTH_DOMAINFIREBASE_DATABASE_URLFIREBASE_STORAGE_BUCKETFIREBASE_SERVICE_ACCOUNT_JSON
App:
SECRET_KEY- Flask session secretGOOGLE_CLIENT_ID- OAuthGOOGLE_CLIENT_SECRET- OAuthSMTP_HOST,SMTP_PORT,SMTP_USERNAME,SMTP_PASSWORD- Email
π Project Structure
Diabetes-Risk-predictor/
βββ flask_app.py # Main application (lazy loading)
βββ auth.py # Authentication
βββ firebase_config.py # Firebase integration
βββ report_generator.py # PDF generation
βββ requirements.txt # Dependencies
βββ startup.sh # Gunicorn config
β
βββ artifacts/ # ML models
β βββ model.pkl # XGBoost model
β βββ scaler.pkl # Feature scaler
β
βββ src/ # ML pipeline
β βββ data_ingestion.py
β βββ data_transformation.py
β βββ model_trainer.py
β
βββ frontend/ # React app
β βββ src/
β βββ components/
β βββ pages/
β βββ lib/
β
βββ templates/ # Flask templates
βββ static/ # Static files
π― ML Model
Features (10 total)
- Pregnancies
- Glucose Level
- Blood Pressure
- Skin Thickness
- Insulin Level
- BMI
- Diabetes Pedigree Function
- Age
- BMI Γ Age (engineered)
- Glucose/Insulin Ratio (engineered)
Performance
- Accuracy: 95.2%
- Precision: 94.8%
- Recall: 93.5%
- F1-Score: 94.1%
β‘ Performance Optimizations
Lazy Loading
Heavy libraries load only when needed:
- NumPy β First prediction
- Matplotlib β Graph generation
- LangChain β Chatbot use
- Firebase β Database access
Result: <30 second startup (was 10+ minutes!)
Gunicorn Config
gunicorn --bind=0.0.0.0:8000 \
--workers=1 --threads=8 \
--timeout=60 --preload \
--worker-class=gthread \
flask_app:app
π Security
β
Environment variables for secrets
β
Firebase security rules
β
Input validation
β
CSRF protection
β
HTTPS-only production
β
Secure sessions
π API Endpoints
Health Check
GET /health
β {"status": "healthy", "timestamp": "..."}
Predict
POST /predict
Headers: Cookie (auth required)
Body: {
"name": "John Doe",
"age": 45,
"glucose": 120,
...
}
β {
"success": true,
"prediction": "Low Risk",
"confidence": 92.5
}
Chatbot
POST /chatbot
Body: {"message": "What is diabetes?"}
β {"response": "...", "timestamp": "..."}
π Troubleshooting
App Not Starting (503)
# Check Azure logs
az webapp log tail --name diabetes-predictor-ai
# Verify health endpoint
curl https://diabetes-predictor-ai.azurewebsites.net/health
Firebase Errors
- Check
firebase-service-account.jsonexists - Verify Firebase security rules
- Validate environment variables
Model Errors
- Verify
artifacts/model.pklexists - Check scaler loaded correctly
- Validate input data format
π€ Contributing
- Fork repository
- Create feature branch
- Commit changes
- Push to branch
- Open Pull Request
π₯ Author
Chapala Naveen Kumar
- GitHub: @Naveenkumar-2007
- Project: Diabetes Predictor
π License
MIT License
π Acknowledgments
- Pima Indians Diabetes Dataset
- Flask, React, Azure communities
- Groq for fast LLM inference
β Star this repo if helpful!
π Live: https://diabetes-predictor-ai.azurewebsites.net