Spaces:
Runtime error
Runtime error
import streamlit as st | |
import pickle | |
import json | |
import pandas as pd | |
# from sklearn.pipeline import make_pipeline | |
# from sklearn.preprocessing import StandardScaler, OneHotEncoder | |
# from sklearn.svm import SVC | |
# from sklearn.linear_model import LogisticRegression | |
# from sklearn.tree import DecisionTreeClassifier | |
# from sklearn.ensemble import RandomForestClassifier | |
with open('svc_model.pkl', 'rb') as f: | |
pipesvc = pickle.load(f) | |
with open('logreg_model.pkl', 'rb') as f: | |
pipeLR = pickle.load(f) | |
with open('dt_model.pkl', 'rb') as f: | |
pipeDT = pickle.load(f) | |
with open('rf_model.pkl', 'rb') as f: | |
pipeRF = pickle.load(f) | |
with open('preprocessor.pkl', 'rb') as f: | |
preprocessor = pickle.load(f) | |
with open('le.pkl', 'rb') as f: | |
Le = pickle.load(f) | |
with open('num_cols.json', 'r') as f: | |
numerical_cols = json.load(f) | |
with open('cat_cols.json', 'r') as f: | |
categorical_cols = json.load(f) | |
def run(): | |
with st.form(key='form_prediksi'): | |
name = st.text_input('Nama', value='') | |
sex = st.radio('Kelamin', ('Perempuan', 'Laki-Laki')) | |
if sex=='Laki-Laki': | |
sexnum='M' | |
else: sexnum='F' | |
age= st.number_input('Umur', min_value=16, max_value=80, value=50, step=1) | |
smoking = st.radio('Apakah merokok?', ('Ya', 'Tidak')) | |
if smoking=='Ya': | |
smokingnum=2 | |
else: smokingnum=1 | |
Yelfing= st.radio('Apakah memiliki Yellow Finger?', ('Ya', 'Tidak')) | |
if Yelfing=='Ya': | |
yelfingnum=2 | |
else: yelfingnum=1 | |
anxeity = st.radio('Apakah memiliki Anxeity?', ('Ya', 'Tidak')) | |
if anxeity == 'Ya': | |
anxeitynum=2 | |
else: anxeitynum=1 | |
peer_pressure = st.radio('Apakah terdapat peer pressure?', ('Ya', 'Tidak')) | |
if peer_pressure=='Ya': | |
peer_pressurenum=2 | |
else: peer_pressurenum=1 | |
Crondis= st.radio('Apakah memiliki penyakit Kronis?', ('Ya', 'Tidak')) | |
if Crondis=='Ya': | |
crondisnum=2 | |
else: crondisnum=1 | |
Fatigue= st.radio('Apakah mudah capai?', ('Ya', 'Tidak')) | |
if Fatigue=='Ya': | |
fatiguenum=2 | |
else: fatiguenum=1 | |
alergi= st.radio('Apakah memiliki alergi?', ('Ya', 'Tidak')) | |
if alergi=='Ya': | |
alerginum=2 | |
else: alerginum=1 | |
mengi= st.radio('Apakah mengidap mengi?', ('Ya', 'Tidak')) | |
if mengi=='Ya': | |
menginum=2 | |
else: menginum=1 | |
Alkohol= st.radio('Apakah mengkonsumsi alkohol?', ('Ya', 'Tidak')) | |
if Alkohol=='Ya': | |
alkoholnum=2 | |
else: alkoholnum=1 | |
batuk= st.radio('Apakah ada batuk?', ('Ya', 'Tidak')) | |
if batuk=='Ya': | |
batuknum=2 | |
else: batuknum=1 | |
sesak= st.radio('Apakah terdapat sesak?', ('Ya', 'Tidak')) | |
if sesak=='Ya': | |
sesaknum=2 | |
else: sesaknum=1 | |
sutel= st.radio('Apakah susah untuk menalan?', ('Ya', 'Tidak')) | |
if sutel=='Ya': | |
sutelnum=2 | |
else: sutelnum=1 | |
sakda= st.radio('Apakah terdapat sakit di bagian dada?', ('Ya', 'Tidak')) | |
if sakda=='Ya': | |
sakdanum=2 | |
else: sakdanum=1 | |
submitted = st.form_submit_button('Predict') | |
data_inf = {'GENDER':sexnum, | |
'AGE': age, | |
'SMOKING':smokingnum, | |
'YELLOW_FINGERS':yelfingnum, | |
'ANXIETY':anxeitynum, | |
'PEER_PRESSURE':peer_pressurenum, | |
'CHRONIC DISEASE':crondisnum, | |
'FATIGUE ':fatiguenum, | |
'ALLERGY ':alerginum, | |
'WHEEZING':menginum, | |
'ALCOHOL CONSUMING':alkoholnum, | |
'COUGHING':batuknum, | |
'SHORTNESS OF BREATH':sesaknum, | |
'SWALLOWING DIFFICULTY':sutelnum, | |
'CHEST PAIN':sakdanum | |
} | |
if submitted: | |
data_inf = pd.DataFrame([data_inf]) | |
# y_pred_inf_rf = pipeRF.predict(data_inf) | |
# y_pred_inf_DT = pipeDT.predict(data_inf) | |
y_pred_inf_LR = pipeLR.predict(data_inf) | |
# y_pred_inf_SVC = pipesvc.predict(data_inf) | |
# st.write('# hasil inf dari Randomforest', Le.inverse_transform(y_pred_inf_rf)) | |
# st.write('# hasil inf dari Decision Tree', Le.inverse_transform(y_pred_inf_DT)) | |
# st.write('# hasil inf dari SVC', Le.inverse_transform(y_pred_inf_SVC)) | |
st.write('# hasil inf dari Logistic Regression', Le.inverse_transform(y_pred_inf_LR)) | |
if __name__== '__main__': | |
run() |