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_hypertension = unique_values["hypertension"] unique_heart_disease = unique_values["heart_disease"] unique_work_type = unique_values["work_type"] unique_smoking_status = unique_values["smoking_status"] def main(): st.title("Stroke Prediction") with st.form("questionaire"): gender = st.selectbox("Gender", options=unique_gender) age = st.slider("Age", min_value=10, max_value=100) hypertension = st.selectbox("Hypertension", options=unique_hypertension) heart_disease = st.selectbox("Heart_Disease", options=unique_heart_disease) work_type = st.selectbox("Work_type", options=unique_work_type) glucose_level = st.slider("Glucose_Level", min_value=0, max_value=300) bmi = st.slider("BMI", min_value=0, max_value=50) smoking = st.selectbox("Smoking", 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], "work_type": [work_type], "avg_glucose_level": [glucose_level], "bmi": [bmi], "smoking_status": [smoking]})) # Show prediction result = 'Yes' if result[0] == 1 else 'No' st.success("Your predicted Stroke is "+result) # Run main() if __name__ == "__main__": main()