Heart-Disease / app.py
rohitashva's picture
Upload 3 files
ad2a718 verified
import streamlit as st
import numpy as np
import joblib
# Load the trained model
model = joblib.load("heart_disease_model.pkl")
# Streamlit UI
st.title("Heart Disease Prediction App")
st.write("Enter patient details below and get a prediction.")
# Input Fields
age = st.number_input("Age", min_value=1, max_value=120, value=50)
sex = st.radio("Sex", ["Male", "Female"])
cp = st.selectbox("Chest Pain Type (CP)", [0, 1, 2, 3])
trestbps = st.number_input("Resting Blood Pressure (mm Hg)", min_value=80, max_value=200, value=120)
chol = st.number_input("Cholesterol (mg/dL)", min_value=100, max_value=600, value=200)
fbs = st.radio("Fasting Blood Sugar > 120 mg/dL", ["No", "Yes"])
restecg = st.selectbox("Resting ECG Results", [0, 1, 2])
thalach = st.number_input("Max Heart Rate Achieved", min_value=60, max_value=220, value=150)
exang = st.radio("Exercise-Induced Angina", ["No", "Yes"])
oldpeak = st.number_input("ST Depression Induced by Exercise", min_value=0.0, max_value=6.0, step=0.1, value=1.0)
slope = st.selectbox("Slope of the Peak Exercise ST Segment", [0, 1, 2])
ca = st.selectbox("Number of Major Vessels (0-3)", [0, 1, 2, 3])
thal = st.selectbox("Thalassemia Type", [0, 1, 2, 3])
# Convert categorical values to numerical
sex = 1 if sex == "Male" else 0
fbs = 1 if fbs == "Yes" else 0
exang = 1 if exang == "Yes" else 0
# Predict button
if st.button("Predict"):
# Create input array
input_data = np.array([[age, sex, cp, trestbps, chol, fbs, restecg, thalach, exang, oldpeak, slope, ca, thal]])
# Make prediction
prediction = model.predict(input_data)[0]
# Display result
if prediction == 1:
st.error("🚨 High Risk: The patient is likely to have heart disease.")
else:
st.success("✅ Low Risk: The patient is unlikely to have heart disease.")