miraaqib704/Heart-Attack-Risk-Prediction-Project
2
1import streamlit as st2import numpy as np3import joblib as jl4# Initialize your trained model5model = jl.load('best_model.pkl')6 7#Define the layout of the web application8st.title("Heart Attack Risk Prediction")9st.markdown("Enter the following information to predict your risk of a heart attack.")10 11# Define the user input fields12age = st.number_input("Age", min_value=1, max_value=120, value=30)13sex = st.selectbox("Sex", ["Male", "Female"])14cp = st.selectbox("Chest Pain Type", [0, 1, 2, 3])15trtbps = st.number_input("Resting Blood Pressure", min_value=1, max_value=300, value=120)16chol = st.number_input("Serum Cholesterol", min_value=1, max_value=1000, value=200)17fbs = st.selectbox("Fasting Blood Sugar > 120 mg/dl", [0, 1])18restecg = st.selectbox("Resting Electrocardiographic Results", [0, 1, 2])19thalachh = st.number_input("Maximum Heart Rate Achieved", min_value=1, max_value=300, value=150)20exng = st.selectbox("Exercise Induced Angina", [0, 1])21#oldpeak = st.number_input("ST Depression Induced by Exercise", min_value=0.0, max_value=10.0, value=0.0)22#slp = st.selectbox("Slope of the Peak Exercise ST Segment", [0, 1, 2])23caa = st.number_input("Number of Major Vessels Colored by Flourosopy", min_value=0, max_value=4, value=0)24#thal = st.selectbox("Thalassemia", [0, 1, 2, 3])25 26# Define the predict button27if st.button("Predict"):28 # Preprocess the user input29 sex = 1 if sex == "Male" else 030 input_data = np.array([[age, sex, cp, trtbps, chol, fbs, restecg, thalachh, exng, caa]])31 32 # Make a prediction on the user input33 prediction = model.predict(input_data)34 35 # Display the prediction to the user36 if prediction == 0:37 st.markdown("### Result: **Low Risk** of a Heart Attack")38 else:39 st.markdown("### Result: **High Risk** of a Heart Attack")40 