File size: 1,810 Bytes
9a33d54
496007c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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)