Skip to content

rahul-roy56/flask-heart-disease-api

Repository files navigation

🚀 Heart Disease Prediction API

Welcome to the Heart Disease Prediction API, a Flask-based microservice designed to predict the likelihood of heart disease using a machine learning model. This project is powered by Random Forest Classification, and the model has been trained on clinical patient data.

Heart Health

🌟 Features

Predicts heart disease risk using real clinical parameters
RESTful API built with Flask
Machine Learning Model trained using Random Forest Classifier
Scalable Deployment using Gunicorn & Flask-RESTful
Preprocessed Input Data with StandardScaler
Interactive Frontend Form for easy predictions


🏗️ Project Structure

📂 flask-heart-disease-api
│-- 📂 static              # Static assets (CSS, JS, images)
│-- 📂 templates           # Frontend HTML files
│-- 📄 app.py              # Main Flask API
│-- 📄 train_model.py      # Script to train & save ML model
│-- 📄 requirements.txt    # Dependencies
│-- 📄 README.md           # Project documentation
│-- 📄 heart.csv           # Dataset used for training
│-- 📄 model.pkl           # Trained ML model
│-- 📄 scaler.pkl          # Standard Scaler object

🛠️ Installation & Setup

🔹 1. Clone the Repository

git clone https://github.com/yourusername/flask-heart-disease-api.git
cd flask-heart-disease-api

🔹 2. Create a Virtual Environment & Install Dependencies

python -m venv venv
source venv/bin/activate  # On macOS/Linux
venv\Scripts\activate    # On Windows
pip install -r requirements.txt

🔹 3. Run the Flask API

python app.py

By default, the API runs at http://127.0.0.1:5000/


🎯 API Usage

🔹 1. Predict Heart Disease (POST Request)

Endpoint: /predict
Content-Type: application/json

📥 Example Request:

{
  "age": 55,
  "sex": 1,
  "cp": 2,
  "trestbps": 130,
  "chol": 250,
  "fbs": 0,
  "restecg": 1,
  "thalach": 150,
  "exang": 1,
  "oldpeak": 2.5,
  "slope": 1,
  "ca": 2,
  "thal": 3
}

📤 Example Response:

{
  "prediction": "Heart Disease",
  "probability": 0.85
}

🎨 Frontend Form

This project includes an interactive HTML form for easy predictions. Just open index.html in your browser, fill in the details, and get instant results!


🚀 Deployment (Optional)

You can deploy this project on Render, AWS, or Heroku using Gunicorn.

gunicorn app:app -b 0.0.0.0:8000

📝 License

This project is open-source and free to use. Feel free to contribute or improve! 💡

🔗 Connect with me: LinkedIn | GitHub
📩 Contact: roy.rah@northeastern.edu

💖 Stay heart-healthy and keep coding! 🚀