import streamlit as st import numpy as np import pandas as pd import matplotlib.pyplot as plt import pickle import json # Load All Files with open('gbc_model.pkl', 'rb') as file_1: gbc_model = pickle.load(file_1) with open('scaler.pkl', 'rb') as file_2: scaler = pickle.load(file_2) # bikin fungsi def run(): with st.form(key='patient_condition'): anemia = st.selectbox('Anemia', (0, 1), index=1, help= '0 = No, \n 1 = yes') diabetes = st.selectbox('Diabetes', (0, 1), index=1, help= '0 = No, \n 1 = yes') high_blood_pressure = st.selectbox('High blood pressure', (0, 1), index=1, help= '0 = No, \n 1 = yes') serum_sodium = st.slider('Serum Sodium', 100, 150, 120) sex = st.selectbox('Sex', (0, 1), index=1, help= '0 = Woman, \n 1 = Man') smoking = st.selectbox('Smoking', (0, 1), index=1, help= '0 = No, \n 1 = yes') time = st.number_input('Time', min_value=100, max_value=150, value=100) binned_age = st.selectbox('Range of age', (1, 2,3,4), index=1, help= '1 = 40-50, \n 2 = 50-60, \n 3 = 60-70, \n 4 = >70') binned_creat_serum = st.selectbox('High serum creatinine', (1, 2), index=1, help= '1 = Normal, \n 2 = High') binned_cpk = st.selectbox('CPK Value', (1,2,3), index=1, help= '1 = Normal, \n 2 = Medium, \n 3 =Dangerous') binned_ejection = st.selectbox(' Ejection fraction', (1,2,3), index=1, help= '1 = Normal, \n 2 = Attention, \n 3 = Dangerous') binned_platelets = st.selectbox('Platelets count', (0, 1, 2), index=1, help='0 = low, \n 1 = normal, \n 2 = high ') st.markdown('---') submitted = st.form_submit_button('Predict') data_inf = { 'anemia': anemia, 'diabetes': diabetes, 'high_blood_pressure' : high_blood_pressure, 'serum_sodium': serum_sodium, 'sex': sex, 'smoking': smoking, 'time': time, 'binned_age': binned_age, 'binned_creat_serum' : binned_creat_serum, 'binned_cpk' : binned_cpk, 'binned_ejection' : binned_ejection, 'binned_platelets': binned_platelets } data_inf = pd.DataFrame([data_inf]) st.dataframe(data_inf) if submitted: # Feature Scaling and Feature Encoding col_headers = list(data_inf.columns.values) data_inf_scaled = scaler.transform(data_inf) data_inf_df = pd.DataFrame(data_inf_scaled, columns=col_headers) # Predict using gbc y_pred_inf = gbc_model.predict(data_inf_df) st.write('# Death possibility: ', str(int(y_pred_inf))) if __name__ == '__main__': run()