Spaces:
Sleeping
Sleeping
Add application file
Browse files- tmp/app.py +80 -0
tmp/app.py
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
from PIL import Image
|
5 |
+
import pickle
|
6 |
+
# formata o valor na moeda brasileira
|
7 |
+
import locale
|
8 |
+
|
9 |
+
# Esconder os menu padrao
|
10 |
+
hide_streamlit_style = """
|
11 |
+
<style>
|
12 |
+
#MainMenu {visibility: hidden;}
|
13 |
+
footer {visibility: hidden;}
|
14 |
+
</style>
|
15 |
+
"""
|
16 |
+
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
|
17 |
+
|
18 |
+
st.title('Sistema de Seguro de Saúde')
|
19 |
+
st.sidebar.title("Informe os dados")
|
20 |
+
|
21 |
+
# variaveis
|
22 |
+
atributos = ['idade', 'sexo', 'IMC', 'num_filhos', 'fumante', 'regiao']
|
23 |
+
# prever o 'valor_seguro']
|
24 |
+
|
25 |
+
dict_categorias = {'sexo': {'Feminino': 0, 'Masculino': 1},
|
26 |
+
'fumante': {'nao': 0, 'sim': 1},
|
27 |
+
'regiao': {'sul': 0, 'sudeste': 1, 'Norte': 2, 'Nordeste': 3}
|
28 |
+
}
|
29 |
+
|
30 |
+
with st.sidebar:
|
31 |
+
|
32 |
+
with st.form(key='my_form'):
|
33 |
+
|
34 |
+
# [ 'idade', 'sexo', 'IMC', 'num_filhos', 'fumante', 'regiao']
|
35 |
+
|
36 |
+
idade = st.number_input('idade', min_value=0, max_value=150, step=1, value=30)
|
37 |
+
|
38 |
+
cat_sexo = st.selectbox('sexo', options=list(dict_categorias['sexo'].keys()))
|
39 |
+
sexo = dict_categorias['sexo'][cat_sexo]
|
40 |
+
|
41 |
+
IMC = st.number_input('IMC', min_value=10.0, max_value=350.0, value=25.0, step=1.0)
|
42 |
+
|
43 |
+
num_filhos = st.number_input('num_filhos', min_value=0, max_value=300, value=2)
|
44 |
+
|
45 |
+
cat_fumante = st.selectbox('fumante',options=list(dict_categorias['fumante'].keys()))
|
46 |
+
fumante = dict_categorias['fumante'][cat_fumante]
|
47 |
+
|
48 |
+
cat_regiao = st.selectbox('região',options=list(dict_categorias['regiao'].keys()))
|
49 |
+
regiao = dict_categorias['regiao'][cat_regiao]
|
50 |
+
|
51 |
+
predict_button = st.form_submit_button(label='Prever')
|
52 |
+
|
53 |
+
|
54 |
+
# Pagina pricipal
|
55 |
+
arquivo_modelo = 'modelo.pkl'
|
56 |
+
with open(arquivo_modelo, 'rb') as f:
|
57 |
+
modelo = pickle.load(f)
|
58 |
+
|
59 |
+
def previsao_seguro(modelo, idade, sexo, IMC, num_filhos, fumante, regiao):
|
60 |
+
|
61 |
+
new_X = np.array([idade, sexo, IMC, num_filhos, fumante, regiao])
|
62 |
+
valor_seguro = modelo.predict(new_X.reshape(1, -1) )[0]
|
63 |
+
return valor_seguro
|
64 |
+
|
65 |
+
imagem = 'seguro.jpeg'
|
66 |
+
|
67 |
+
image = Image.open(imagem)
|
68 |
+
st.image(image, width=500)
|
69 |
+
|
70 |
+
if predict_button:
|
71 |
+
valor_seguro = previsao_seguro(modelo, idade, sexo, IMC, num_filhos, fumante, regiao)
|
72 |
+
|
73 |
+
locale.setlocale(locale.LC_ALL, 'pt_BR.UTF-8')
|
74 |
+
str_valor_seguro = locale.currency(valor_seguro, grouping=True, symbol=None)
|
75 |
+
str_valor_seguro_mensal = locale.currency(valor_seguro / 12, grouping=True, symbol=None)
|
76 |
+
st.markdown('## Valor do Seguro (Anual): R$ ' + str_valor_seguro )
|
77 |
+
st.markdown('## Valor Mensal: R$ ' + str_valor_seguro_mensal )
|
78 |
+
|
79 |
+
|
80 |
+
|