import streamlit as st import pandas as pd import numpy as np import json import joblib # load file joblib dengan .pkl with open('model_rf.pkl', 'rb') as file_1: model_rf= joblib.load(file_1) with open('model_scaler.pkl', 'rb') as file_2: model_scaler= joblib.load(file_2) #loan file txt dengan json.load with open('list_num_cols.txt', 'r') as file_3: num_columns= json.load(file_3) def run() : with st.form(key='from_heart_failure'): #name = st.text_input('Full Name', value='') age = st.number_input('Age', min_value=25, max_value=100, value=25, step=1, help='Usia Pasien') sex = st.selectbox('Sex', ('Man', 'Woman'), index=1) smoking = st.selectbox('Smoking', ('No', 'Yes'), index=1) st.markdown('---') phosphokinase = st.slider('Creatinine Phosphokinase', min_value=23, max_value=7861, value=70) fraction = st.slider('Ejection Fraction', 10, 90, 50) platelets = st.slider('Platelets', 25000, 900000, 125000) creatinine = st.number_input('Serum Creatinine', min_value=0.0, max_value=10.0, value=0.0, step=0.1) sodium = st.slider('Serum Sodium', 100, 148, 120) time = st.slider('Time', 1, 300, 1) st.markdown('---') anaemia = st.selectbox('Have Anaemia', ('No', 'Yes'), index=1) diabetes = st.selectbox('Have Diabetes', ('No', 'Yes'), index=1) high_blood_pressure = st.selectbox('Have High Blood Pressure', ('No', 'Yes'), index=1) DEATH_EVENT = st.selectbox('Death Event', ('Survived', 'Dead'), index=1) submitted = st.form_submit_button('Predict') data_inf = { 'age': age, 'anaemia': anaemia, 'creatin_phosphokinase: ': phosphokinase, 'diabetes': diabetes, 'ejection_fraction': fraction, 'high_blood_pressure': high_blood_pressure, 'platelets': platelets, 'serum_creatinine': creatinine, 'serum_sodium': sodium, 'sex': sex, 'smoking': smoking, 'time': time, 'DEATH_EVENT': DEATH_EVENT, } data_inf = pd.DataFrame([data_inf]) data_inf if submitted: #Numerical Columns data_inf_num = data_inf[num_columns] # Feature Scaling data_inf_final = model_scaler.transform(data_inf_num) # Predict using Random Forest y_pred_inf = model_rf.predict(data_inf_final) prediction_label = "Survived" if y_pred_inf == 0 else "Dead" st.write('# Rating : ', prediction_label) if __name__== '__main__': run()