HeartDiseasePredictorUsingANN / src /streamlit_app.py
IbrhaimBajwa313's picture
Update src/streamlit_app.py
496007c verified
import streamlit as st
import numpy as np
from keras.models import load_model
import joblib
# Load model and scaler
model = load_model("model.keras")
scaler = joblib.load("scaler.pkl")
st.set_page_config(page_title="Heart Disease Predictor", layout="centered")
st.title("πŸ«€ Heart Disease Prediction")
# User inputs
age = st.number_input("Age", 20, 100)
sex = st.selectbox("Sex", ["Male", "Female"])
resting_bp = st.number_input("Resting Blood Pressure", 80, 200)
cholesterol = st.number_input("Cholesterol", 100, 600)
fasting_bs = st.selectbox("Fasting Blood Sugar > 120 mg/dl", [0, 1])
max_hr = st.number_input("Max Heart Rate", 60, 250)
exercise_angina = st.selectbox("Exercise Induced Angina", ["Yes", "No"])
oldpeak = st.number_input("Oldpeak", 0.0, 10.0, step=0.1)
st_slope = st.selectbox("ST Slope", ["Up", "Flat", "Down"])
chest_pain = st.selectbox("Chest Pain Type", ["ATA", "NAP", "ASY", "TA"])
# Encode categorical variables
sex = 1 if sex == "Male" else 0
exercise_angina = 1 if exercise_angina == "Yes" else 0
st_slope_flat = 1 if st_slope == "Flat" else 0
st_slope_up = 1 if st_slope == "Up" else 0
chest_pain_asy = 1 if chest_pain == "ASY" else 0
chest_pain_nap = 1 if chest_pain == "NAP" else 0
chest_pain_ta = 1 if chest_pain == "TA" else 0
# Input array
input_data = np.array([[age, sex, resting_bp, cholesterol, fasting_bs, max_hr, exercise_angina, oldpeak,
st_slope_flat, st_slope_up,
chest_pain_asy, chest_pain_nap, chest_pain_ta]])
# Prediction
if st.button("Predict"):
scaled_input = scaler.transform(input_data)
prediction = model.predict(scaled_input)
result = "πŸ’” Heart Disease Detected" if prediction[0][0] > 0.5 else "❀️ No Heart Disease Detected"
st.subheader("Prediction Result")
st.success(result)