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.
| 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 |
# 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:5000cardioai_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
| 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).

| Variable | Description |
|---|---|
GEMINI_API_KEY |
Get free at aistudio.google.com |
FLASK_SECRET_KEY |
Any random string |
FLASK_ENV |
development or production |
| 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 |
- β 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
- 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-
Go to render.com β New β Web Service β Connect your GitHub repo
-
Render auto-detects
render.yamlandDockerfile -
Add your
GEMINI_API_KEYin Render dashboard β Environment -
Click Deploy β your app goes live at
https://cardioai.onrender.com
# Build
docker build -t cardioai .
# Run
docker run -p 5000:5000 -e GEMINI_API_KEY=your_key cardioai
# Open http://localhost:5000
Mehr Ali β BS Computer Science, FAST NUCES
MIT License β see LICENSE for details.