Lutfidts/DiabetesPrediciton_
0
1import streamlit as st2import pandas as pd3import numpy as np4import joblib5import base646 7from keras.models import load_model8 9 10import warnings11warnings.filterwarnings("ignore")12 13 14st.markdown("<h2 style='text-align: center;'>Diabetes Prediction</h2>", unsafe_allow_html=True)15st.markdown('---'*10)16 17model_final = joblib.load('sklearn_pipeline.pkl')18model_final.named_steps['modeling'].model = load_model('model_keras.h5')19 20pilihan = st.selectbox('Apa yang ingin Anda lakukan?',['Prediksi dari file excel','Input Manual'])21 22if pilihan == 'Prediksi dari file excel':23 def set_bg_1(main_bg):24 25 main_bg_ext = "jpg"26 27 st.markdown(28 f"""29 <style>30 .stApp {{31 background: url(data:image/{main_bg_ext};base64,{base64.b64encode(open(main_bg, "rb").read()).decode()});32 background-position: center;33 background-size: 720px 520px;34 background-repeat: no-repeat35 }}36 </style>37 """,38 unsafe_allow_html=True39 )40 set_bg_1('diabtescheck.jpg')41 42 # Mengupload file43 upload_file = st.file_uploader('Pilih file excel', type='xlsx')44 if upload_file is not None:45 dataku1 = pd.read_excel(upload_file)46 dataku1.rename(columns={"concave points_mean":"concave_points_mean","concave points_se":"concave_points_se","concave points_worst":"concave_points_worst"}, inplace=True)47 dataku = dataku1.copy()48 dataku.drop(['id'],axis=1,inplace=True)49 #dataku.drop(columns='diagnosis',axis=0,inplace=True)50 st.write(dataku1)51 st.success('File berhasil diupload')52 if st.button('Diabetes Prediction'):53 hasil = model_final.predict(dataku)54 #st.write('Prediksi',hasil)55 # Keputusan56 for i in range(len(hasil)):57 if hasil[i] == 1:58 st.write("ID ",dataku1['id'][i]," diprediksi Yes")59 else:60 st.write("ID ",dataku1['id'][i]," diprediksi No")61 else:62 st.error('File yang diupload kosong, silakan pilih file yang valid')63 #st.markdown('File yang diupload kosong, silakan pilih file yang valid')64else:65 def set_bg_2(main_bg):66 67 main_bg_ext = "jpg"68 69 st.markdown(70 f"""71 <style>72 .stApp {{73 background: url(data:image/{main_bg_ext};base64,{base64.b64encode(open(main_bg, "rb").read()).decode()});74 background-position: center;75 background-size: 720px 520px;76 background-repeat: no-repeat77 }}78 </style>79 """,80 unsafe_allow_html=True81 )82 set_bg_2('diabetic.jpg')83 84 #185 with st.container():86 col1, col2 = st.columns(2)87 with col1:88 Pregnancies = st.number_input('Pregnancies', value=0.41)89 with col2:90 PlasmaGlucose = st.number_input('PlasmaGlucose', value=0.75)91 92 #293 with st.container():94 col1, col2 = st.columns(2)95 with col1:96 DiastolicBloodPressure = st.number_input('DiastolicBloodPressure', value=0.63)97 with col2:98 TricepsThickness = st.number_input('TricepsThickness', value=0.29)99 100 #3101 with st.container():102 col1, col2 = st.columns(2)103 with col1:104 SerumInsulin = st.number_input('SerumInsulin', value=0.14)105 with col2:106 BMI = st.number_input('BMI', value=0.52)107 108 #4109 with st.container():110 col1, col2 = st.columns(2)111 with col1:112 DiabetesPedigree = st.number_input('DiabetesPedigree', value=0.26)113 with col2:114 Age = st.number_input('Age', value=0.55)115 116 117 # Inference118 data = {119 'Pregnancies': Pregnancies,120 'PlasmaGlucose': PlasmaGlucose,121 'DiastolicBloodPressure': DiastolicBloodPressure,122 'TricepsThickness': TricepsThickness,123 'SerumInsulin': SerumInsulin,124 'BMI': BMI,125 'DiabetesPedigree': DiabetesPedigree,126 'Age': Age, 127 }128 129 130 # Tabel data131 kolom = list(data.keys())132 df = pd.DataFrame([data.values()], columns=kolom)133 134 mystyle = '''135 <style>136 p {137 text-align: center;138 font-weight: bold;139 font-weight: 100px140 }141 </style>142 '''143 144 # Memunculkan hasil di Web 145 st.write('***'*10)146 if st.button('Breast Cancer Classification'):147 prediksi = model_final.predict(df)148 if (prediksi[0] == 1):149 st.write(mystyle,'1',unsafe_allow_html=True)150 else:151 st.write(mystyle,'0',unsafe_allow_html=True)152 