riri-soltan-99's picture
Update app.py
db93dde
import streamlit as st
import numpy as np
import joblib as jl
import xgboost as xgb
import pickle
# Load the model from the file
with open('xgb_classifier_model_heart.pkl', 'rb') as model_file:
loaded_xgb_model = pickle.load(model_file)
# Define the layout of the web application
st.title("Heart Attack Risk Prediction")
st.markdown("Enter the following information to predict your risk of a Heart Attack.")
# Define the user input fields
sex = st.selectbox("Sex", ["Male", "Female"])
chest_pain = st.selectbox("Chest Pain", ["Typical Angina", "Atypical Angina", "Non-Anginal pain", "Asymptomatic"])
Max_heartrate_achieved = st.number_input("Maximum Heartrate Achieved ")
Exercice_angina = st.selectbox("Exercise Induced Angina", ["Yes", "No"])
oldpeak = st.number_input("oldpeak")
slop = st.selectbox("Slope of the peak exercise ST segment", ["Unsloping", "flat", "Downsloping"])
nb_vessels = st.selectbox("Number of major vessels", ["0", "1", "2", "3"])
thal = st.selectbox("Thalassemia", ["Null", "Fixed defect", "Normal", "Reversible defect"])
# Define the predict button
if st.button("Predict"):
# Preprocess the user input
sex = 1 if sex == "Male" else 0
chest_pain = 0 if chest_pain == "Typical Angina" else 1 if chest_pain == "Atypical Angina" else 2 if chest_pain == "Non-Anginal pain" else 3
Exercice_angina = 1 if Exercice_angina == "Yes" else 0
slop = 0 if slop == "Unsloping" else 1 if slop == "flat" else 2 if slop == "Downsloping" else 0
nb_vessels = 0 if nb_vessels == "0" else 1 if nb_vessels == "1" else 2 if nb_vessels == "2" else 3
thal = 0 if thal == "Null" else 1 if thal == "Fixed defect" else 2 if thal == "Normal" else 3 if thal == "Reversible defect" else 0
input_data = np.array([[sex, chest_pain, Max_heartrate_achieved, Exercice_angina,oldpeak, slop, nb_vessels, thal]])
# Make a prediction on the user input
prediction = loaded_xgb_model.predict(input_data)
# Display the prediction to the user
if prediction == 0:
st.markdown("### Result: **Low Risk** of a Heart Attack")
else:
st.markdown("### Result: **High Risk** of a Heart Attack")