Mummia-99's picture
Update app.py
59a6a3c verified
import streamlit as st
import joblib
import numpy as np
## Heading
html_temp = """
<div style="background-color:black;padding:10px">
<h2 style="color:red;text-align:center;">Cardiovascular Health Prediction App </h2>
</div>
"""
st.markdown(html_temp, unsafe_allow_html=True)
# st.markdown(html_temp, unsafe_allow_html=True)
# image
url="https://static.vecteezy.com/system/resources/previews/006/712/964/original/abstract-health-medical-science-healthcare-icon-digital-technology-doctor-concept-modern-innovation-treatment-medicine-on-hi-tech-future-blue-background-for-wallpaper-template-web-design-vector.jpg"
st.image(url, use_container_width=True)
st.markdown(f"""
<style>
/* Set the background image for the entire app */
.stApp {{
background-color:#fdf5df;
background-size: 100px;
background-repeat:no;
background-attachment: auto;
background-position:full;
}}
</style>
""", unsafe_allow_html=True)
st.write("Enter the Patient details:")
# model
health_model=joblib.load("health_model.joblib")
scaler_model=joblib.load('scaler_the data_model.joblib')
# Input variables
col1, col2 = st.columns(2)
with col1:
## Age
age=st.slider("Slide the AGE of the Patient:",max_value=80,min_value=20)
with col2:
## gender
option_gen=["Female "," Male"]
gen=st.selectbox("Select the Gender",option_gen)
gender_value=option_gen.index(gen)
col1, col2 = st.columns(2)
with col1:
## chestpain
chestpain=st.slider("Slide the chestpain Value:",min_value=0,max_value=3)
with col2:
## restingBP
restingBP=st.slider("Slide the Resting BP of the Patient:",min_value=90,max_value=200)
col1,col2=st.columns(2)
with col1:
## serumcholestrol
serumcholestrol=st.slider("Slide The Serum cholestrol Of a Ptient :",min_value=0,max_value=600)
with col2:
## fastingbloodsugar
fastingbloodsugar= st.radio("Is Patient blood is Fasting:", ["YES", "NO"])
if fastingbloodsugar=="YES":
fastingbloodsugar_value=1
else:
fastingbloodsugar_value=0
col1,col2=st.columns(2)
with col1:
## restingrelectro
restingrelectro=st.slider("Slide The restingrelectro of a Patient :",min_value=0,max_value=2)
with col2:
## maxheartrate
maxheartrate=st.slider("Slide The max heart rate of the Patient :",min_value=70,max_value=200)
col1,col2=st.columns(2)
with col1:
## exerciseangia
exerciseangia=st.slider("Slide the exerciseangia Value:",min_value=0,max_value=1)
with col2:
##oldpeak'
oldpeak=st.slider("Silde the oldpeak :",max_value=6.2,min_value=0.0,value=0.1)
col1,col2=st.columns(2)
with col1:
## slope
slope=st.slider("Silde the slope of the Patient :",max_value=3,min_value=0,value=1)
with col2:
## noofmajorvessels
noofmajorvessels=st.slider("Silde the No of Major Vessels to a Patient :",max_value=3,min_value=0,value=1)
if st.button("Submit"):
# st.write("before scaleing:",[age,gender_value,chestpain,restingBP,serumcholestrol,fastingbloodsugar_value,restingrelectro,
# maxheartrate,exerciseangia,oldpeak,slope,noofmajorvessels])
# Scaler the values
scaler_val = scaler_model.transform([[age,gender_value,chestpain,restingBP,serumcholestrol,fastingbloodsugar_value,restingrelectro,
maxheartrate,exerciseangia,oldpeak,slope,noofmajorvessels]])
# st.write("after scaleing:",scaler_val)
try:
prediction=health_model.predict(scaler_val)[0]
# Define messages and colors
review_status = {
0: ("βœ… The patient is Healthy", "#32CD32"), # Green
1: ("❌ The Patient has Heart Disease ", "#FF4500") # Red-Orange
}
# Get message and color based on prediction
message, color = review_status.get(prediction, ("❓ Unknown Prediction", "#808080"))
# Display styled result
st.markdown(f"""
<div style="
padding: 15px;
background-color: {color};
border-radius: 10px;
text-align: center;
font-size: 18px;
font-weight: bold;
color: white;">
{message}
</div>
""", unsafe_allow_html=True)
except Exception as e:
st.error(f"⚠️ Error in prediction: {e}")