Heart disease predictor

🫀 A simple ML-powered REST API using FastAPI to predict heart disease based on patient data. It uses a trained scikit-learn model and provides real-time predictions from features like age, sex, cholesterol, and blood pressure.

image
NextJs

nextjs

TailwindCSS

tailwind

TS

typescript

🫀 Heart Disease Predictor

FULL STACK ML PROJECT

A machine learning-powered web application to predict the likelihood of heart disease based on patient health data. Built with FastAPI for the backend and Next.js for the frontend.

🚀 Live Demo

🔗 Site

Home Page

🧠 Tech Stack

  • Frontend: Next.js, Tailwind CSS, React
  • Backend: FastAPI, joblib (for model loading)
  • Model: Trained with Scikit-learn on a heart disease dataset
  • Deployment: Vercel (frontend), Railway (backend)

📊 Features

  • Input patient data like age, cholesterol, blood pressure, etc.
  • Get instant prediction (0 = No heart disease, 1 = Potential heart disease)

📦 Backend Setup

Prerequisites

  • Python 3.8+
  • pip install -r requirements.txt

Run locally

uvicorn main:app --reload

Deployment

  • The backend is deployed using Railway.
  • Ensure the following files are present:
    • model.pkl – Trained ML model
    • scaler.pkl – StandardScaler used during training
    • columns.pkl – Feature column names used for prediction

CORS Setup

app.add_middleware(
    CORSMiddleware,
    allow_origins=["https://heart-disease-predictor-phi.vercel.app"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

API Endpoint

POST /predict

Request Body (JSON)

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

Response

{
  "prediction": 1
}

Made with ❤️ by kishore-sv