-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
94 lines (70 loc) · 2.74 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import pickle
import numpy as np
import pandas as pd
import streamlit as st
import sklearn
loaded_model = pickle.load(open('streamlit_insurance_predictcharges.pkl', 'rb'))
from PIL import Image
image = Image.open('hospital2.jpg')
image_hospital = Image.open('hospital.jpg')
st.title("ML App :sunglasses:")
html_temp = """
<div style="background-color:teal ;padding:10px">
<h2 style="color:white;text-align:center;">Prediccion de Gastos por Seguros</h2>
</div>
"""
st.markdown(html_temp, unsafe_allow_html=True)
st.image(image,use_column_width=False)
add_selectbox = st.sidebar.selectbox(
"Como le gustaría predecir?",
("Online", "Lote"))
st.sidebar.info('Esta aplicación está creada para predecir los gastos hospitalarios de los pacientes')
st.sidebar.success('https://github.com/waloZarate')
st.sidebar.image(image_hospital)
if add_selectbox == 'Online':
#st.title("Predict insurance charges")
st.write("""*:point_right: @ML app desarrollada por Oswaldo L. Zárate*""")
def load_data():
df = pd.DataFrame({'sex': ['Male','Female'],
'smoker': ['Yes', 'No']})
return df
df = load_data()
def load_data():
df1 = pd.DataFrame({'region' : ['southeast' ,'northwest' ,'southwest' ,'northeast']})
return df1
df1 = load_data()
sex = st.selectbox("Seleccione Genero", df['sex'].unique())
smoker = st.selectbox("Usted fuma?", df['smoker'].unique())
region = st.selectbox("A que región de Estados Unidos pertenece?", df1['region'].unique())
age = st.slider("Cual es su edad?", 18, 100)
bmi = st.slider("Cual es su IMC?", 10, 60)
children = st.slider("Número de hijos", 0, 10)
if sex == 'male':
gender = 1
else:
gender = 0
if smoker == 'yes':
smoke = 1
else:
smoke = 0
if region == 'southeast':
reg = 2
elif region == 'northwest':
reg = 3
elif region == 'southwest':
reg = 1
else:
reg = 0
features = [gender, smoke, reg, age, bmi, children]
int_features = [int(x) for x in features]
final_features = [np.array(int_features)]
st.info('Pulse el boton **Predecir** para ver el resultado:')
if st.button('Predecir'): # when the submit button is pressed
prediction = loaded_model.predict(final_features)
st.balloons()
st.success(f'Your insurance charges would be: ${round(prediction[0],2)}')
if add_selectbox == 'Lote':
file_upload = st.file_uploader("Upload csv file para predicciones", type=["csv"])
if file_upload is not None:
data = pd.read_csv(file_upload)
st.write(data)