Diabetes / README.md
Naveen-2007's picture
Add HuggingFace metadata to README
fcf75d5
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.

Azure Deployment HuggingFace Python 3.11 Flask 3.0 React

🌐 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 LLM
  • PINECONE_API_KEY - Vector DB

Firebase (10 secrets):

  • FIREBASE_API_KEY
  • FIREBASE_PROJECT_ID
  • FIREBASE_PRIVATE_KEY_ID
  • FIREBASE_CLIENT_EMAIL
  • FIREBASE_CLIENT_ID
  • FIREBASE_AUTH_DOMAIN
  • FIREBASE_DATABASE_URL
  • FIREBASE_STORAGE_BUCKET
  • FIREBASE_SERVICE_ACCOUNT_JSON

App:

  • SECRET_KEY - Flask session secret
  • GOOGLE_CLIENT_ID - OAuth
  • GOOGLE_CLIENT_SECRET - OAuth
  • SMTP_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.json exists
  • Verify Firebase security rules
  • Validate environment variables

Model Errors

  • Verify artifacts/model.pkl exists
  • Check scaler loaded correctly
  • Validate input data format

🀝 Contributing

  1. Fork repository
  2. Create feature branch
  3. Commit changes
  4. Push to branch
  5. Open Pull Request

πŸ‘₯ Author

Chapala Naveen Kumar

πŸ“„ 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