Sony2713/_Heart_Failure_Prediction_
0
1import streamlit as st2import numpy as np3import joblib4from tensorflow.keras.models import load_model5 6# Load the ANN model and scaler7model = load_model("model.h5") # ✅ Loads your saved Keras model8scaler = joblib.load("scaler.pkl") # ✅ Loads your saved StandardScaler9 10# Streamlit app UI11st.set_page_config(page_title="Heart Failure Predictor", layout="centered")12st.title("❤ Heart Failure Risk Prediction")13st.markdown("Enter patient details to check the *risk of heart failure*.")14 15# Input form16age = st.number_input("Age", min_value=18, max_value=100, step=1)17anaemia = st.selectbox("Anaemia", ["No", "Yes"])18creatinine_phosphokinase = st.number_input("Creatinine Phosphokinase", min_value=0)19diabetes = st.selectbox("Diabetes", ["No", "Yes"])20ejection_fraction = st.slider("Ejection Fraction (%)", min_value=10, max_value=80)21high_blood_pressure = st.selectbox("High Blood Pressure", ["No", "Yes"])22platelets = st.number_input("Platelets (kilo per mL)", min_value=25000.0, max_value=850000.0)23serum_creatinine = st.number_input("Serum Creatinine", min_value=0.0, max_value=10.0)24serum_sodium = st.number_input("Serum Sodium", min_value=100.0, max_value=150.0)25sex = st.selectbox("Sex", ["Female", "Male"])26smoking = st.selectbox("Smoking", ["No", "Yes"])27time = st.slider("Follow-up Time (days)", min_value=0, max_value=300)28 29# Convert to model-ready input30input_data = np.array([[31 age,32 1 if anaemia == "Yes" else 0,33 creatinine_phosphokinase,34 1 if diabetes == "Yes" else 0,35 ejection_fraction,36 1 if high_blood_pressure == "Yes" else 0,37 platelets,38 serum_creatinine,39 serum_sodium,40 1 if sex == "Male" else 0,41 1 if smoking == "Yes" else 0,42 time43]])44 45# Scale the input46input_scaled = scaler.transform(input_data)47 48# Predict and show result49if st.button("Predict"):50 prediction = model.predict(input_scaled).round()[0][0]51 if prediction == 1:52 st.error("⚠ High Risk of Heart Failure")53 else:54 st.success("✅ Low Risk of Heart Failure")