valencar commited on
Commit
5392719
·
verified ·
1 Parent(s): 3ec5b9d

Upload 7 files

Browse files
LANA_Card.png ADDED
app_diabetes.py ADDED
@@ -0,0 +1,332 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ # import xgboost as xgb
4
+ # import xgboost
5
+ import pickle
6
+ import numpy as np
7
+ from PIL import Image
8
+
9
+ # Remove whitespace from the top of the page
10
+ reduce_header_height_style = """
11
+ <style> .stDeployButton {visibility: hidden;} </style>
12
+ <style> div[class^='block-container'] { padding-top: 1rem; } </style>
13
+ """
14
+ st.markdown(reduce_header_height_style, unsafe_allow_html=True)
15
+
16
+ # predict_button = None
17
+
18
+
19
+ # Pagina pricipal
20
+
21
+ def previsao_diabetes(modelo, Pressao_Alta, Colesterol_Alto, Checagem_Colesterol_em_5_anos, IMC, Fumante, AVC,
22
+ Doenca_coronaria_cardiaca, Atividade_Fisica_nos_ultimos_30_dias,
23
+ Consumo_Frutas, Consumo_Vegetais, Alto_Consumo_Alcool,
24
+ Plano_de_Saude, Nao_pode_ir_ao_medico_devido_custo, Estado_Geral_Saude,
25
+ Saude_mental, Saude_fisica, Dificuldade_andar_ou_subir_escadas, Sexo,
26
+ Idade, Nivel_Educacional, Renda):
27
+ # 0 = no diabetes 1 = prediabetes 2 = diabetes
28
+
29
+ new_X = np.array([Pressao_Alta, Colesterol_Alto, Checagem_Colesterol_em_5_anos, IMC, Fumante, AVC,
30
+ Doenca_coronaria_cardiaca, Atividade_Fisica_nos_ultimos_30_dias,
31
+ Consumo_Frutas, Consumo_Vegetais, Alto_Consumo_Alcool,
32
+ Plano_de_Saude, Nao_pode_ir_ao_medico_devido_custo, Estado_Geral_Saude,
33
+ Saude_mental, Saude_fisica, Dificuldade_andar_ou_subir_escadas, Sexo,
34
+ Idade, Nivel_Educacional, Renda])
35
+
36
+ xgb = modelo
37
+
38
+ # Colocar em escala (Padronizacao)
39
+ import joblib as jb
40
+ sc = jb.load('std_scaler.bin')
41
+ scaler_X = sc.transform(new_X.reshape(1, -1)) # fit_transform
42
+
43
+ preds = xgb.predict(scaler_X.reshape(1,-1))[0]
44
+ print(scaler_X)
45
+ probabilidades = xgb.predict_proba(scaler_X.reshape(1,-1))[0]
46
+ probabilidade = np.max(np.array(probabilidades))
47
+ probabilidade = int(round(probabilidade * 100, 0))
48
+
49
+ diagnostico_previsto = preds
50
+
51
+
52
+ if diagnostico_previsto == 0:
53
+ Diagnostico_Diabetes = ":blue[Sem Diabetes]"
54
+ image = 'saudavel.jpg'
55
+ elif diagnostico_previsto == 1:
56
+ Diagnostico_Diabetes = ":red[Diabetes tipo 2]"
57
+ image = 'diabetes02.jpg'
58
+ else:
59
+ Diagnostico_Diabetes = "Sem Diagnóstico"
60
+
61
+ return Diagnostico_Diabetes, image, probabilidade
62
+
63
+
64
+ if __name__=="__main__":
65
+
66
+ st.title('Sistema para Previsão de Diabetes Tipo 2')
67
+
68
+ # carregando o modelo
69
+ if 'xgb' not in st.session_state:
70
+ with st.spinner('carregando o modelo...'):
71
+ file = 'modeloXGBoost_Diabetes.pkl'
72
+ with open(file, 'rb') as f:
73
+ xgb = pickle.load(f)
74
+
75
+ with st.container():
76
+ col1 = st.container()
77
+
78
+ def format_func(option):
79
+ return CHOICES[option]
80
+
81
+ st.sidebar.title("Atributos")
82
+
83
+ # # variaveis
84
+ atributos = ['Diagnostico_Diabetes', 'Pressao_Alta', 'Colesterol_Alto', 'Checagem_Colesterol_em_5_anos', 'IMC', 'Fumante', 'AVC', 'Doenca_coronaria_cardiaca', 'Atividade_Fisica_nos_ultimos_30_dias', 'Consumo_Frutas', 'Consumo_Vegetais', 'Alto_Consumo_Alcool', 'Plano_de_Saude', 'Nao_pode_ir_ao_medico_devido_custo', 'Estado_Geral_Saude', 'Saude_mental', 'Saude_fisica', 'Dificuldade_andar_ou_subir_escadas', 'Sexo', 'Idade', 'Nivel_Educacional', 'Renda']
85
+
86
+ # inicializacao das variaveis
87
+ Diagnostico_Diabetes= Pressao_Alta= Colesterol_Alto= Checagem_Colesterol_em_5_anos= IMC= Fumante= AVC= Doenca_coronaria_cardiaca= Atividade_Fisica_nos_ultimos_30_dias= Consumo_Frutas= Consumo_Vegetais= Alto_Consumo_Alcool= Plano_de_Saude= Nao_pode_ir_ao_medico_devido_custo= Estado_Geral_Saude= Saude_mental= Saude_fisica= Dificuldade_andar_ou_subir_escadas= Sexo= Idade= Nivel_Educacional= Renda = 0
88
+
89
+ with st.sidebar: # scrolling=True
90
+ with st.form(key='my_form'):
91
+
92
+ CHOICES = {0: "Não", 1: "Sim"}
93
+ Pressao_Alta = st.selectbox('Pressão Alta', options=list(CHOICES.keys()), format_func=format_func)
94
+ Colesterol_Alto = st.selectbox('Colesterol Alto',options=list(CHOICES.keys()), format_func=format_func)
95
+ Checagem_Colesterol_em_5_anos = st.selectbox(
96
+ 'Checagem colesterol em 5 anos',options=list(CHOICES.keys()), format_func=format_func)
97
+
98
+ imc = IMC = st.number_input('IMC', min_value=25.0, max_value=500.0, step=1.0)
99
+ if (imc >= 0 and imc < 18):
100
+ imc_int = 17
101
+ elif (imc >= 18 and imc <= 24):
102
+ imc_int = 24
103
+ elif (imc > 24 and imc <= 30):
104
+ imc_int = 30
105
+ elif (imc > 30 and imc <= 35):
106
+ imc_int = 35
107
+ elif (imc > 35 and imc <= 40):
108
+ imc_int = 40
109
+ else:
110
+ imc_int = 41
111
+ IMC = imc_int
112
+
113
+ CHOICES = {0: "Não", 1: "Sim"}
114
+ Fumante = st.selectbox('Fumante',options=list(CHOICES.keys()), format_func=format_func)
115
+
116
+ CHOICES = {0: "Não", 1: "Sim"}
117
+ AVC = st.selectbox('AVC',options=list(CHOICES.keys()), format_func=format_func)
118
+
119
+ CHOICES = {0: "Não", 1: "Sim"}
120
+ Doenca_coronaria_cardiaca = st.selectbox('Doenca coronária cardíaca',
121
+ options=list(CHOICES.keys()), format_func=format_func)
122
+
123
+ CHOICES = {0: "Não", 1: "Sim"}
124
+ # physical activity in past 30 days - not including job 0 = no 1 = yes
125
+ Atividade_Fisica_nos_ultimos_30_dias = st.selectbox(
126
+ 'Atividade Física nos últimos 30 dias',
127
+ options=list(CHOICES.keys()), format_func=format_func)
128
+
129
+
130
+ CHOICES = {0: "Não", 1: "Sim"}
131
+ Consumo_Frutas = st.selectbox('Consumo de Frutas',options=list(CHOICES.keys()), format_func=format_func)
132
+
133
+ Consumo_Vegetais = st.selectbox('Consumo de Vegetais',options=list(CHOICES.keys()), format_func=format_func)
134
+
135
+ Alto_Consumo_Alcool = st.selectbox('Alto Consumo de Alcool',options=list(CHOICES.keys()), format_func=format_func)
136
+
137
+ Plano_de_Saude = st.selectbox('Plano de Saúde',options=list(CHOICES.keys()), format_func=format_func)
138
+
139
+ Nao_pode_ir_ao_medico_devido_custo = st.selectbox(
140
+ 'Não pode ir ao medico devido ao custo',options=list(CHOICES.keys()), format_func=format_func)
141
+
142
+ # 1 = excellent 2 = very good 3 = good 4 = fair 5 = poor
143
+ CHOICES = {1: "Excelente" , 2: "Muito Bom", 3: "Bom", 4: "Razoável", 5: "Ruim"}
144
+ Estado_Geral_Saude = st.selectbox('Estado Geral de Saúde',
145
+ options=list(CHOICES.keys()), format_func=format_func)
146
+
147
+ valor = Saude_mental = st.number_input('Problemas com Saude Mental (em dias)',
148
+ min_value=0, max_value=30)
149
+ if (valor == 0):
150
+ valor_categoria = 0
151
+ elif (valor == 1):
152
+ valor_categoria = 1
153
+ elif (valor == 2):
154
+ valor_categoria = 2
155
+ elif (valor > 2 and valor <= 29):
156
+ valor_categoria = 29
157
+ elif (valor == 30):
158
+ valor_categoria = 30
159
+ Saude_mental = valor_categoria
160
+
161
+ valor = Saude_fisica = st.number_input('Problemas com Saude Física (em dias)',
162
+ min_value=0, max_value=30)
163
+ if (valor == 0):
164
+ valor_categoria = 0
165
+ elif (valor == 1):
166
+ valor_categoria = 1
167
+ elif (valor == 2):
168
+ valor_categoria = 2
169
+ elif (valor > 2 and valor <= 29):
170
+ valor_categoria = 29
171
+ elif (valor == 30):
172
+ valor_categoria = 30
173
+ Saude_fisica = valor_categoria
174
+
175
+
176
+ Dificuldade_andar_ou_subir_escadas = st.selectbox(
177
+ 'Dificuldade de andar ou subir escadas',options=list(CHOICES.keys()), format_func=format_func)
178
+
179
+ CHOICES = {0: "Maculino", 1: "Feminino"}
180
+ Sexo = st.selectbox('Sexo',options=list(CHOICES.keys()), format_func=format_func)
181
+
182
+ CHOICES = {1: "18-24", 2: "25-29", 3: "30-34", 4: "35-39", 5: "40-44", 6: "45-49", 7: "50-54",
183
+ 8: "55-59", 9: "60-64", 10: "65-69", 11: "70-74", 12: "75-79", 13:"80+"}
184
+ valor = Idade = st.selectbox('Idade', options=list(CHOICES.keys()), format_func=format_func)
185
+ if (valor == 1):
186
+ valor_categoria = 6
187
+ elif (valor == 2):
188
+ valor_categoria = 6
189
+ elif (valor == 3):
190
+ valor_categoria = 6
191
+ elif (valor == 4):
192
+ valor_categoria = 6
193
+ elif (valor == 5):
194
+ valor_categoria = 6
195
+ elif (valor == 6):
196
+ valor_categoria = 6
197
+ elif (valor == 7):
198
+ valor_categoria = 8
199
+ elif (valor == 8):
200
+ valor_categoria = 8
201
+ elif (valor == 9):
202
+ valor_categoria = 9
203
+ elif (valor == 10):
204
+ valor_categoria = 10
205
+ elif (valor == 11):
206
+ valor_categoria = 13
207
+ elif (valor == 12):
208
+ valor_categoria = 13
209
+ elif (valor == 13):
210
+ valor_categoria = 13
211
+ Idade = valor_categoria
212
+
213
+ # Educação - 1 = Never attended school or only kindergarten 2 = Grades 1 through 8 (Elementary) 3 = Grades 9 through 11 (Some high school) 4 = Grade 12 or GED (High school graduate) 5 = College 1 year to 3 years (Some college or technical school) 6 = College 4 years or more (College graduate)
214
+ CHOICES = {1: 'Não frequentou a escola', 2: 'Ensino Básico', 3: 'Ensino Médio Incompleto',
215
+ 4: 'Ensino Médio Completo', 4: "Faculdade (1 a 3 anos) ou Técnico",
216
+ 5: "Superior Completo" }
217
+ valor = Nivel_Educacional = st.selectbox('Nivel Educacional',
218
+ options=list(CHOICES.keys()), format_func=format_func)
219
+ if (valor == 1):
220
+ valor_categoria = 2
221
+ elif (valor == 2):
222
+ valor_categoria = 2
223
+ elif (valor == 3):
224
+ valor_categoria = 3
225
+ elif (valor == 4):
226
+ valor_categoria = 4
227
+ elif (valor == 5):
228
+ valor_categoria = 5
229
+ elif (valor == 6):
230
+ valor_categoria = 6
231
+ Nivel_Educacional = valor_categoria
232
+
233
+
234
+ CHOICES = { 1:'Menos de $10,000', 2:'$10,000 até menos que $15,000',
235
+ 3:'$15,000 até menos que $20,000', 4:'$20,000 até menos que $25,000',
236
+ 5:'$25,000 até menos que $35,000', 6:'$35,000 até menos que $50,000',
237
+ 7:'$50,000 até menos que $75,000', 8:'Mais de $75,000' }
238
+
239
+ valor = Renda = st.selectbox('Renda Anual (em Dólar)',
240
+ options=list(CHOICES.keys()), format_func=format_func)
241
+ if (valor == 1):
242
+ valor_categoria = 1
243
+ elif (valor == 2):
244
+ valor_categoria = 1
245
+ elif (valor == 3):
246
+ valor_categoria = 1
247
+ elif (valor == 4):
248
+ valor_categoria = 1
249
+ elif (valor == 5):
250
+ valor_categoria = 5
251
+ elif (valor == 6):
252
+ valor_categoria = 6
253
+ elif (valor == 7):
254
+ valor_categoria = 7
255
+ elif (valor == 8):
256
+ valor_categoria = 8
257
+ Renda = valor_categoria
258
+
259
+ predict_button = st.form_submit_button(label='Prever')
260
+
261
+
262
+ if predict_button: # is not None:
263
+
264
+ # atributos_por_ordem =[ \
265
+ # 'HighBP', 'HighChol', 'CholCheck', 'Smoker', 'Stroke',
266
+ # 'HeartDiseaseorAttack', 'PhysActivity', 'Fruits', 'Veggies',
267
+ # 'HvyAlcoholConsump', 'AnyHealthcare', 'NoDocbcCost', 'GenHlth',
268
+ # 'DiffWalk', 'Sex', 'MentHlth_cat', 'PhysHlth_cat', 'Income_cat',
269
+ # 'Education_cat', 'BMI_cat', 'Age_cat']
270
+
271
+ # ['HighBP' 'HighChol' 'CholCheck' 'Smoker' 'Stroke'
272
+ # 'HeartDiseaseorAttack', 'PhysActivity' 'Fruits' 'Veggies',
273
+ # 'HvyAlcoholConsump', 'AnyHealthcare' 'NoDocbcCost' 'GenHlth'
274
+ # 'DiffWalk' 'Sex' 'MentHlth_cat' 'PhysHlth_cat''Income_cat'
275
+ # 'Education_cat' 'BMI_cat' 'Age_cat']
276
+
277
+ Diagnostico_Diabetes, imagem, probabilidade = previsao_diabetes(xgb,
278
+ Pressao_Alta, Colesterol_Alto, Checagem_Colesterol_em_5_anos, Fumante, AVC,
279
+ Doenca_coronaria_cardiaca, Atividade_Fisica_nos_ultimos_30_dias, Consumo_Frutas, Consumo_Vegetais,
280
+ Alto_Consumo_Alcool, Plano_de_Saude, Nao_pode_ir_ao_medico_devido_custo, Estado_Geral_Saude,
281
+ Dificuldade_andar_ou_subir_escadas, Sexo, Saude_mental, Saude_fisica, Renda,
282
+ Nivel_Educacional, IMC, Idade)
283
+
284
+ image = Image.open(imagem)
285
+ #st.markdown('## Diagnóstico: ' + Diagnostico_Diabetes + " - " + str(probabilidade) + "%")
286
+ #st.write('Diagnóstico:' + Diagnostico_Diabetes)
287
+ #st.image(image, width=250)
288
+ string_saida = 'Diagnóstico: ' + Diagnostico_Diabetes + " - " + str(probabilidade) + "%"
289
+ col1.header(string_saida)
290
+ col1.image(image, width=700)
291
+ else:
292
+ imagem = 'diabetes_desktop.jpg'
293
+ image = Image.open(imagem)
294
+ # st.image(image, width=250)
295
+ col1.image(image, width=700)
296
+
297
+ # main()
298
+ st.write("")
299
+ st.write("")
300
+ st.write("")
301
+ st.write("")
302
+ st.write("")
303
+
304
+ aviso = "ESTE RESULTADO NÃO SUBSTITUI A AVALIAÇÃO DO MÉDICO. Este é um sistema para auxílio diagnóstico de doenças usando modelos ensemble. Todo o processamento é feito no seu dispositivo e as imagens não são enviadas para o seu servidor. Ao continuar, você assume toda a responsabilidade com o uso."
305
+ st.markdown(f'<div style="color: #856404; background-color: #fff3cd; border-color: #ffeeba; padding-top:10px; padding-top:10px; padding-bottom:10px; padding-left:10px; padding-right:10px;">{aviso}</div>',
306
+ unsafe_allow_html=True)
307
+
308
+
309
+ st.write("")
310
+ st.write("")
311
+
312
+ st.write("")
313
+ st.write("")
314
+ st.write("")
315
+ st.write("")
316
+ st.write("")
317
+
318
+
319
+ footer="\
320
+ <div > \
321
+ <p>Sistema de Apoio ao Diagnóstico de Diabetes tipo 2 versão 1.0.1.<br> \
322
+ Desenvolvido por Prof. Dr. Vladimir Costa de Alencar e Equipe de Pesquisadores do LANA/UEPB. <br> \
323
+ Campina Grande, Paraíba, Brasil, 2024.<br> \
324
+ <a href='https://www.valencar.com' target='_blank'>www.valencar.com</a></p>"
325
+ st.markdown(footer, unsafe_allow_html=True)
326
+
327
+ name_image = "LANA_Card.png"
328
+ imagem = Image.open(name_image)
329
+ st.image(imagem, width=300)
330
+
331
+
332
+
diabetes02.jpg ADDED
diabetes_desktop.jpg ADDED
modeloXGBoost_Diabetes.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b6fa9e22651f62c6a2775eed1e29f9c880c8fe93f7b70c8af1e3c1de19258370
3
+ size 3036528
saudavel.jpg ADDED
std_scaler.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4aa77a137b23aa4216e89ff8a74e6bb35f92ff3f39de32a8cfc3bfcca22adfc3
3
+ size 1359