File size: 4,604 Bytes
7d513e2
 
 
 
03feec9
2ef1240
03feec9
7d513e2
 
 
 
 
 
 
f8c4603
c7b806d
7d513e2
 
 
2e54c82
2069f6a
7d513e2
 
 
0fc7b4d
7d513e2
 
 
 
 
29404ec
7d513e2
 
 
 
 
 
 
 
 
c7b806d
9828ecc
7d513e2
c7b806d
 
7d513e2
 
 
 
 
 
 
 
c74a49d
 
7d513e2
 
2ef1240
 
 
 
 
310c92f
17736a7
 
 
7d513e2
 
 
3fd6242
 
 
 
 
 
 
6718647
8629c90
c7b806d
 
cd025b1
8629c90
c7b806d
 
 
 
2ef1240
3fd6242
2ef1240
ce4a789
7d513e2
 
 
 
 
 
 
 
 
 
 
 
 
 
310c92f
7d513e2
 
 
 
 
03feec9
310c92f
 
7d513e2
 
 
9828ecc
7d513e2
 
 
 
 
 
 
 
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import streamlit as st
import numpy as np
import keras
from keras.preprocessing import image
from huggingface_hub import from_pretrained_keras
import random

# Remove whitespace from the top of the page
reduce_header_height_style = """
    <style> .stDeployButton {visibility: hidden;} </style>
    <style> div[class^='block-container'] { padding-top: 1rem; } </style> 
"""
st.markdown(reduce_header_height_style, unsafe_allow_html=True)


def predict_image(file_name):

	IMAGE_HEIGHT, IMAGE_WIDTH = 299, 299
	categories = ['Normal', 'Tuberculose']

	img = img_orig = image.load_img(file_name, target_size = (IMAGE_HEIGHT, IMAGE_WIDTH))
	img = image.img_to_array(img)
	img = np.expand_dims(img, axis = 0)
	img = img/255.0
  
	pred = st.session_state.model.predict(img)
	classe = np.argmax(pred)
	nome_classe = categories[classe]
	prob = np.max(pred)

#	col1.image(img_orig, width=450)
	mensagem = "Previsão: " + categories[classe] + ' - ' + str(round(prob * 100)) + '%' 
	str_prob = ' - ' + f"{(prob*100):.3f}"[:-2] + '%' 

	if int(classe) == 0: 
		classe_prevista = ':blue[Normal]'
	else:
		classe_prevista = ':red[Tuberculose]'

	msg = 'Previsão: ' + classe_prevista + str_prob
	#col1.header(msg)
	#print(mensagem)

	return msg


titulo = 'Classificação - Doenças Pulmonares'
st.markdown(f'<div style="padding-top:30px; padding-bottom:2px; font-size:40px;font-weight:bold">{titulo}</div>', 
	unsafe_allow_html=True) 

@st.cache_data
def inicializa_modelo():
	print('carregando o modelo...')
	file = "valencar/modelo_raios_x"
	model = from_pretrained_keras(file)		
	print('modelo carregado.')
	return model

def escolher_imagem():
	imagens = ['CHNCXR_0342_1.png', 'CHNCXR_0022_0.png', 'CHNCXR_0006_0.png', 'CHNCXR_0004_0.png', 'CHNCXR_0338_1.png', 'CHNCXR_0340_1.png', 'CHNCXR_0020_0.png', 'CHNCXR_0019_0.png', 'CHNCXR_0024_0.png', 'CHNCXR_0344_1.png', 'CHNCXR_0002_0.png', 'CHNCXR_0327_1.png', 'CHNCXR_0346_1.png', 'CHNCXR_0005_0.png', 'CHNCXR_0021_0.png', 'CHNCXR_0341_1.png', 'CHNCXR_0339_1.png', 'CHNCXR_0023_0.png', 'CHNCXR_0343_1.png', 'CHNCXR_0007_0.png', 'CHNCXR_0003_0.png', 'CHNCXR_0347_1.png', 'CHNCXR_0345_1.png', 'CHNCXR_0025_0.png', 'CHNCXR_0018_0.png', 'CHNCXR_0001_0.png', 'CHNCXR_0328_1.png', 'CHNCXR_0350_1.png', 'CHNCXR_0014_0.png', 'CHNCXR_0331_1.png', 'CHNCXR_0349_1.png', 'CHNCXR_0016_0.png', 'CHNCXR_0333_1.png', 'CHNCXR_0337_1.png', 'CHNCXR_0012_0.png', 'CHNCXR_0335_1.png', 'CHNCXR_0010_0.png', 'CHNCXR_0009_0.png', 'CHNCXR_0332_1.png', 'CHNCXR_0017_0.png', 'CHNCXR_0351_1.png', 'CHNCXR_0329_1.png', 'CHNCXR_0348_1.png', 'CHNCXR_0330_1.png', 'CHNCXR_0015_0.png', 'CHNCXR_0011_0.png', 'CHNCXR_0334_1.png', 'CHNCXR_0008_0.png', 'CHNCXR_0013_0.png', 'CHNCXR_0336_1.png']
	imagem = random.sample(imagens, k=1)[0]	
	return imagem

if 'model' not in st.session_state:
	with st.spinner('carregando o modelo...'):
		st.session_state.model = inicializa_modelo()

with st.container():
	col1 = st.container()

	if st.button('Raios-X Diversos'):
		nome_imagem = escolher_imagem()
		imagem = image.load_img(name_image)
		col1.image(imagem)
		col1.header(predict_image(nome_imagem))

	file_upload = st.file_uploader("Carregue uma Imagem de Raios-X:", type="png")

	if file_upload is not None:
		imagem = image.load_img(file_upload)
		col1.image(imagem)
		col1.header(predict_image(file_upload))
	else:
		name_image = "doencas_pulmonares.jpg"
		imagem = image.load_img(name_image)
		col1.image(imagem, width=700)
		


 

st.write("")
st.write("")
st.write("")
st.write("")
st.write("")

aviso = "ESTE RESULTADO NÃO SUBSTITUI A AVALIAÇÃO DO MÉDICO. Este é um sistema para auxílio diagnóstico de doenças usando deep learning. 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."
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>', 
	unsafe_allow_html=True) 


st.write("")
st.write("")

st.write("")
st.write("")
st.write("")
st.write("")
st.write("")




footer="\
<div > \
<p>Sistema de Apoio ao Diagnóstico de Doenças Pulmonares versão 1.0.2.<br> \
Desenvolvido por Prof. Dr. Vladimir Costa de Alencar e Equipe de Pesquisadores do LANA/UEPB. <br> \
Campina Grande, Paraíba, Brasil, 2024.<br> \
<a href='https://www.valencar.com' target='_blank'>www.valencar.com</a></p>"
st.markdown(footer, unsafe_allow_html=True) 

name_image = "LANA_Card.png"
imagem = image.load_img(name_image)
st.image(imagem, width=300)