Chatop's picture
Update app.py
ffe0bde
import joblib
import pandas as pd
import streamlit as st
model = joblib.load('model.joblib')
unique_values = joblib.load('unique_values.joblib')
unique_gender = unique_values["gender"]
unique_ever_married = unique_values["ever_married"]
unique_work_type = unique_values["work_type"]
unique_Residence_type = unique_values["Residence_type"]
unique_smoking_status = unique_values["smoking_status"]
def main():
st.title("Adult Income")
with st.form("questionaire"):
gender = st.selectbox("Sex", options=unique_gender)
age = st.slider("Age", min_value=5, max_value=100)
hypertension = st.radio("Hypertension", ('Have Hypertension',"Doesn't Have Hypertension"))
if hypertension == 'Have Hypertension':
st.write('You selected have Hypertension.')
hypertension = 1
else:
st.write("You selected doesn't have Hypertension.")
hypertension = 0
heart_disease = st.radio("Heart Disease", ('Have Heart Disease', "Doesn't Have Heart Disease",))
if heart_disease == 'Have Heart Disease':
st.write('You selected have Heart Disease.')
heart_disease = 1
else:
st.write("You selected doesn't have Heart Disease.")
heart_disease = 0
ever_married = st.selectbox("Married", options=unique_ever_married)
work_type = st.selectbox("Work Type", options=unique_work_type )
Residence_type = st.selectbox("Residence Type", options=unique_Residence_type )
avg_glucose_level = st.number_input("Avg Glucose Level", min_value=20.0, max_value=300.0)
bmi = st.number_input('BMI:', min_value=10.0, max_value=50.0)
smoking_status = st.selectbox("Smoking Status", options=unique_smoking_status )
# clicked==True only when the button is clicked
clicked = st.form_submit_button("Predict Stroke")
if clicked:
result=model.predict(pd.DataFrame({"gender": [gender],
"age": [age],
"hypertension": [hypertension],
"heart_disease": [heart_disease],
"ever_married": [ever_married],
"work_type": [work_type],
"Residence_type": [Residence_type],
"avg_glucose_level": [avg_glucose_level],
"bmi": [bmi],
"smoking_status": [smoking_status]}))
# Show prediction
result = 'You had a Stroke' if result[0] == 1 else "You didn't have a Stroke"
st.success("Your predicted is "+result)
if __name__ == "__main__":
main()