alnamez/PredictLifeExpectancy_heartfailure
0
1import streamlit as st2import pandas as pd3import numpy as np4import datetime as dt5import joblib6import plotly.express as px7 8# Load the model9with open('bestpipe_adaboost_gc3.pkl', 'rb') as file_1:10 pl_adaboost = joblib.load(file_1)11 12# Define the app header13st.set_page_config(14 page_title="Your Conditions, Your Future",15 page_icon=":heart:",16 layout="wide"17)18 19header = st.container()20with header:21 st.image('header3.png',width=300)22 st.title('Predict Your Life Expectancy')23 24# Define the app inputs25inputs = st.container()26with inputs:27 st.subheader('Tell us about your health')28 age = st.slider('Age', 1, 99)29 ef = st.slider('Ejection Fraction', 14, 80)30 bp = st.selectbox('High Blood Pressure', ('No', 'Yes'))31 creat = st.slider('Serum Creatinine', 0.5, 9.4)32 sodium = st.slider('Serum Sodium', 100, 148)33 followup = st.slider('Follow-Up Period (days)', 4, 285)34 35 if bp == 'Yes':36 high_bp = 137 else:38 high_bp = 039 40 # Create a dataframe with the user inputs41 df = pd.DataFrame({42 'age': [age],43 'ejection_fraction': [ef],44 'high_blood_pressure': [high_bp],45 'serum_creatinine': [creat],46 'serum_sodium': [sodium],47 'time': [followup]48 })49 50 # Create a bar chart to visualize the user input values51 chart_data = pd.DataFrame({'Category': ['Age', 'Ejection Fraction', 'Serum Creatinine', 'Serum Sodium', 'Follow-Up Period'],52 'Value': [age, ef, creat, sodium, followup]})53 fig = px.bar(chart_data, x='Category', y='Value', color='Category', title='Your Health Conditions')54 fig.update_traces(texttemplate='%{y}', textposition='outside')55 fig.update_layout(uniformtext_minsize=8, uniformtext_mode='hide')56 fig.add_annotation(x=0.5, y=1.1,57 xref='paper', yref='paper',58 text='Your Health Conditions',59 showarrow=False,60 font=dict(size=16))61 fig.update_xaxes(title='')62 fig.update_yaxes(title='Value')63 st.plotly_chart(fig)64 65# Define the app output66output = st.container()67with output:68 if st.button('Predict'):69 st.subheader('Prediction:')70 pred = pl_adaboost.predict(df)71 72 if pred[0] == 1:73 st.error('Based on your health conditions, we predict that you will die.')74 else:75 st.success('Congratulations! Based on your health conditions, we predict that you will live longer.')76 77 78 79 