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) diabetes = st.selectbox('Diabetes', (0, 1), index=1) high_blood_pressure = st.selectbox('High blood pressure', (0, 1), index=1) serum_sodium = st.number_input('Serum Sodium', min_value=100, max_value=150, value=100) sex = st.selectbox('Sex', (0, 1), index=1) smoking = st.selectbox('Sex', (0, 1), index=1) 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) binned_creat_serum = st.selectbox('High serum creatinine', (1, 2), index=1) binned_cpk = st.selectbox('CPK Value', (1,2,3), index=1) binned_ejection = st.selectbox(' Ejection frraction', (1,2,3), index=1) binned_cpk = st.selectbox('CPK Value', (1,2,3), index=1) binned_platelets = st.selectbox('Platelets count', (0, 1, 2), index=1) st.markdown('---') submitted = st.form_submit_button('Predict') data_inf = { 'anemia': 1, 'diabetes': 1, 'high_blood_pressure' : 1, 'serum_sodium': 130, 'sex': 1, 'smoking': 1, 'time': 150, 'binned_age': 3, 'binned_creat_serum' : 2, 'binned_cpk' : 2, 'binned_ejection' : 2, 'binned_platelets': 2 } 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('# Rating: ', str(int(y_pred_inf))) if __name__ == '__main__': run()