import joblib import pandas as pd import streamlit as st import category_encoders as ce model = joblib.load('model_tree.joblib') unique_values = joblib.load('unique_values.joblib') SEX_DICT = {'M':1, 'F':2} BP_DICT = {'LOW':1, 'NORMAL':2, 'HIGH':3} Cholesterol_DICT = {'NORMAL':1, 'HIGH':2} unique_Sex = unique_values['Sex'] unique_BP = unique_values['BP'] unique_Cholesterol = unique_values['Cholesterol'] def main(): st.title("Medicine Suggestion") #<-Apps' name with st.form("questionaire"): Age = st.slider('Age',min_value=10,max_value=100) Na_to_K = st.slider('Na_to_K',min_value=1,max_value=50) Sex = st.selectbox('Sex',options=unique_Sex) BP = st.selectbox('BP',options=unique_BP) Cholesterol = st.selectbox('Cholesterol',options=unique_Cholesterol) # clicked==True only when the button is clicked clicked = st.form_submit_button("Predict medicine") if clicked: result=model.predict(pd.DataFrame({"Age": [Age], "Na_to_K": [Na_to_K], "Sex": [SEX_DICT[Sex]], "BP": [BP_DICT[BP]], "Cholesterol": [Cholesterol_DICT[Cholesterol]] })) # Show prediction result = result[0] st.success("You should get " +result) # Run main() if __name__=="__main__": main()