Skip to content
AstreonixPublic

About

An end-to-end AI-powered heart disease risk prediction platform built with Flask, scikit-learn, SHAP explainability, Gemini AI chat, SQLAlchemy, and ReportLab PDF generation.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

15 Commits

Folders and files

Repository files navigation

πŸ«€ CardioAI β€” Heart Disease Risk Prediction Platform

image image

Python Flask scikit-learn SHAP Gemini License Deploy

An end-to-end AI-powered heart disease risk prediction platform built with Flask, scikit-learn, SHAP explainability, Gemini AI chat, SQLAlchemy, and ReportLab PDF generation.


✨ Features

Feature Description
🎯 ML Prediction Random Forest classifier β€” ROC-AUC 0.86
🧠 SHAP Explainability Per-prediction feature impact chart
πŸ’¬ Gemini AI Chat Context-aware cardiovascular health assistant
πŸ“„ PDF Reports Downloadable clinical report with SHAP chart
πŸ—„οΈ Database SQLite via SQLAlchemy β€” predictions + chat history + reports
πŸ”’ Rate Limiting Flask-Limiter protection on all POST routes
βœ… Input Validation Server + client side validation on all 13 fields
πŸ“Š History Dashboard Filter, search, and review all past assessments

πŸš€ Quick Start

# 1. Clone the repo
git clone https://github.com/mehrali-hub/CardioAI.git
cd CardioAI

# 2. Install dependencies
pip install -r requirements.txt

# 3. Set up environment variables
cp .env.example .env
# Edit .env and add your GEMINI_API_KEY

# 4. Run
python app.py

# 5. Open browser
# http://localhost:5000

πŸ“ Project Structure

cardioai_project/
β”œβ”€β”€ app.py                          # Flask app β€” all routes + ML + PDF
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ .env.example                    # Environment variable template
β”‚
β”œβ”€β”€ templates/
β”‚   β”œβ”€β”€ index.html                  # Landing page
β”‚   β”œβ”€β”€ predict.html                # Assessment form + SHAP results
β”‚   β”œβ”€β”€ history.html                # Prediction history dashboard
β”‚   β”œβ”€β”€ chat.html                   # Gemini AI chat assistant
β”‚   └── 404.html                    # Error page
β”‚
β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ cardioai_model.pkl          # Trained Random Forest
β”‚   β”œβ”€β”€ scaler.pkl                  # StandardScaler
β”‚   β”œβ”€β”€ feature_columns.pkl         # Feature list
β”‚   β”œβ”€β”€ model_metadata.pkl          # Metrics + params
β”‚   └── shap_explainer.pkl          # TreeExplainer
β”‚
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ CardioAI_Merged_Heart_Dataset.csv
β”‚   └── processed/                  # Train/test splits
β”‚
β”œβ”€β”€ images/                         # EDA + model plots (9 files)
└── notebooks/
    β”œβ”€β”€ 01_EDA.ipynb
    β”œβ”€β”€ 02_Preprocessing.ipynb
    └── 03_Model_Training.ipynb

πŸ€– Model Performance

Metric Score
ROC-AUC 0.86
Accuracy 76.7%
Precision 76.7%
Recall 76.7%
F1 Score 76.7%

Trained on the UCI Heart Disease dataset (303 patients, 13 features). image

image

πŸ”‘ Environment Variables

Variable Description
GEMINI_API_KEY Get free at aistudio.google.com
FLASK_SECRET_KEY Any random string
FLASK_ENV development or production

πŸ“ Routes

Route Method Description
/ GET Landing page
/predict GET/POST Run ML prediction
/history GET View all assessments
/history/data GET JSON API for history
/chat GET AI chat assistant
/chat/message POST Send message to Gemini
/report/<id> GET Download PDF report

πŸ—οΈ Milestones

image
  • βœ… M1 β€” Documentation
  • βœ… M2 β€” EDA & Visualization
  • βœ… M3 β€” Model Training & Evaluation
  • βœ… M4 β€” Flask Backend (all routes + DB)
  • βœ… M5 β€” Full Frontend (4 pages)
  • βœ… M6 β€” AI Integration, SHAP, PDF, Rate Limiting, Validation
  • βœ… M7 β€” Docker + Render Deployment
  • πŸ”² M8 β€” Kaggle Notebook + Portfolio

🐳 Deployment (M7)

Deploy to Render (Free)

  1. Push to GitHub:
git init
git add .
git commit -m "πŸ«€ CardioAI - Complete ML Platform"
git branch -M main
git remote add origin https://github.com/mehrali-hub/CardioAI.git
git push -u origin main
  1. Go to render.com β†’ New β†’ Web Service β†’ Connect your GitHub repo

  2. Render auto-detects render.yaml and Dockerfile

  3. Add your GEMINI_API_KEY in Render dashboard β†’ Environment

  4. Click Deploy β†’ your app goes live at https://cardioai.onrender.com

Run with Docker locally

# Build
docker build -t cardioai .

# Run
docker run -p 5000:5000 -e GEMINI_API_KEY=your_key cardioai

# Open http://localhost:5000
image

πŸ‘¨β€πŸ’» Author

Mehr Ali β€” BS Computer Science, FAST NUCES
GitHub Kaggle


πŸ“„ License

MIT License β€” see LICENSE for details.

About

An end-to-end AI-powered heart disease risk prediction platform built with Flask, scikit-learn, SHAP explainability, Gemini AI chat, SQLAlchemy, and ReportLab PDF generation.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages