Update app.py
Browse files
app.py
CHANGED
@@ -16,22 +16,39 @@ def image_to_base64(image_path):
|
|
16 |
return base64.b64encode(img_file.read()).decode()
|
17 |
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
20 |
|
21 |
# Dati di esempio predefiniti
|
22 |
esempi = {
|
23 |
-
"Frontal
|
24 |
-
"Frontal
|
25 |
-
"Frontal
|
26 |
-
"Lateral
|
27 |
-
"Lateral
|
28 |
-
"Lateral
|
29 |
-
"Report
|
30 |
-
"Report
|
31 |
-
"Report
|
32 |
-
"Frontal + Lateral
|
33 |
-
"Frontal + Report
|
34 |
-
"Lateral + Report
|
35 |
}
|
36 |
|
37 |
|
@@ -141,7 +158,7 @@ if st.session_state['step'] == 1:
|
|
141 |
|
142 |
# Immagine con didascalia migliorata e con dimensione della caption aumentata
|
143 |
image_path = "./DEMO/Loghi/model_final.png" # Sostituisci con il percorso della tua immagine
|
144 |
-
st.image(image_path, caption='',
|
145 |
|
146 |
# Caption con dimensione del testo migliorata
|
147 |
st.markdown("""
|
@@ -163,10 +180,10 @@ if st.session_state['step'] == 1:
|
|
163 |
if st.session_state['step'] == 2:
|
164 |
# Opzioni disponibili
|
165 |
options = [
|
166 |
-
"Frontal
|
167 |
-
"Lateral
|
168 |
-
"Report
|
169 |
-
"Frontal + Lateral
|
170 |
]
|
171 |
|
172 |
# Messaggio di selezione con dimensione aumentata
|
@@ -220,17 +237,17 @@ if st.session_state['step'] == 3:
|
|
220 |
unsafe_allow_html=True)
|
221 |
|
222 |
# Carica l'immagine frontale
|
223 |
-
if "Frontal" in st.session_state['selected_option'].split("
|
224 |
st.markdown("<h5 style='font-size: 18px;'>Load the Frontal X-ray in DICOM format</h5>", unsafe_allow_html=True)
|
225 |
st.session_state['frontal_file'] = st.file_uploader("", type=["dcm"])
|
226 |
|
227 |
# Carica l'immagine laterale
|
228 |
-
if "Lateral" in st.session_state['selected_option'].split("
|
229 |
st.markdown("<h5 style='font-size: 18px;'>Load the Lateral X-ray in DICOM format</h5>", unsafe_allow_html=True)
|
230 |
st.session_state['lateral_file'] = st.file_uploader("", type=["dcm"])
|
231 |
|
232 |
# Inserisci il report clinico
|
233 |
-
if "Report" in st.session_state['selected_option'].split("
|
234 |
st.markdown("<h5 style='font-size: 18px;'>Type the clinical report</h5>", unsafe_allow_html=True)
|
235 |
st.session_state['report'] = st.text_area("", value=st.session_state['report'])
|
236 |
|
@@ -249,11 +266,11 @@ if st.session_state['step'] == 3:
|
|
249 |
with st.spinner("Preprocessing the data..."):
|
250 |
time.sleep(3)
|
251 |
# Controllo che i file necessari siano stati caricati
|
252 |
-
if "Frontal" in st.session_state['selected_option'].split("
|
253 |
st.error("Load the Frontal image.")
|
254 |
-
elif "Lateral" in st.session_state['selected_option'].split("
|
255 |
st.error("Load the Lateral image.")
|
256 |
-
elif "Report" in st.session_state['selected_option'].split("
|
257 |
st.error("Type the clinical report.")
|
258 |
else:
|
259 |
st.write(f"Execution of: {st.session_state['selected_option']}")
|
@@ -319,20 +336,20 @@ if st.session_state['step'] == 3:
|
|
319 |
st.write(f"Loaded Report: {report}")
|
320 |
|
321 |
inputs = []
|
322 |
-
if "Frontal" in st.session_state['selected_option'].split("
|
323 |
inputs.append('frontal')
|
324 |
-
if "Lateral" in st.session_state['selected_option'].split("
|
325 |
inputs.append('lateral')
|
326 |
-
if "Report" in st.session_state['selected_option'].split("
|
327 |
inputs.append('text')
|
328 |
|
329 |
# Ora vediamo cosa c'Γ¨ dopo la freccia
|
330 |
outputs = []
|
331 |
-
if "Frontal" in st.session_state['selected_option'].split("
|
332 |
outputs.append('frontal')
|
333 |
-
if "Lateral" in st.session_state['selected_option'].split("
|
334 |
outputs.append('lateral')
|
335 |
-
if "Report" in st.session_state['selected_option'].split("
|
336 |
outputs.append('text')
|
337 |
|
338 |
# Ultima cosa che va fatta Γ¨ passare allo step 4, prima di farlo perΓ², tutte le variabili che ci servono
|
@@ -383,26 +400,26 @@ if st.session_state['step'] == 5:
|
|
383 |
unsafe_allow_html=True)
|
384 |
|
385 |
inputs = []
|
386 |
-
if "Frontal" in st.session_state['selected_option'].split("
|
387 |
inputs.append('Frontal')
|
388 |
-
if "Lateral" in st.session_state['selected_option'].split("
|
389 |
inputs.append('Lateral')
|
390 |
-
if "Report" in st.session_state['selected_option'].split("
|
391 |
inputs.append('Report')
|
392 |
|
393 |
outputs = []
|
394 |
-
if "Frontal" in st.session_state['selected_option'].split("
|
395 |
outputs.append('Frontal')
|
396 |
-
if "Lateral" in st.session_state['selected_option'].split("
|
397 |
outputs.append('Lateral')
|
398 |
-
if "Report" in st.session_state['selected_option'].split("
|
399 |
outputs.append('Report')
|
400 |
|
401 |
esempio = esempi[st.session_state['selected_option']]
|
402 |
|
403 |
# Mostra i file associati all'esempio
|
404 |
st.markdown(
|
405 |
-
"<h3 style='text-align:
|
406 |
unsafe_allow_html=True)
|
407 |
|
408 |
# Colonne per gli INPUTS
|
@@ -431,7 +448,7 @@ if st.session_state['step'] == 5:
|
|
431 |
st.write(f"Report: {esempio['Report']}")
|
432 |
|
433 |
st.markdown(
|
434 |
-
"<h3 style='text-align:
|
435 |
unsafe_allow_html=True)
|
436 |
|
437 |
# Colonne per gli OUTPUTS
|
|
|
16 |
return base64.b64encode(img_file.read()).decode()
|
17 |
|
18 |
|
19 |
+
st.markdown("""
|
20 |
+
<style>
|
21 |
+
@font-face {
|
22 |
+
font-family: 'Palatino';
|
23 |
+
font-style: normal;
|
24 |
+
font-weight: 400;
|
25 |
+
src: local('Palatino Linotype'), local('Book Antiqua'),
|
26 |
+
url(https://fonts.gstatic.com/s/cardo/v22/wlp_gwIBjINFON1YNFX6WcrrlQ.ttf) format('truetype');
|
27 |
+
}
|
28 |
+
/* Applica il font a tutto */
|
29 |
+
html, body, [class*="st"] {
|
30 |
+
font-family: 'Palatino', serif;
|
31 |
+
}
|
32 |
+
</style>
|
33 |
+
""", unsafe_allow_html=True)
|
34 |
+
|
35 |
+
|
36 |
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
37 |
|
38 |
# Dati di esempio predefiniti
|
39 |
esempi = {
|
40 |
+
"Frontal β Lateral": {'Frontal': 'FtoL.png', 'Lateral': 'LfromF.png'},
|
41 |
+
"Frontal β Report": {'Frontal': '31d9847f-987fcf63-704f7496-d2b21eb8-63cd973e.tiff', 'Report': 'Small bilateral pleural effusions, left greater than right.'},
|
42 |
+
"Frontal β Lateral + Report": {'Frontal': '81bca127-0c416084-67f8033c-ecb26476-6d1ecf60.tiff', 'Lateral': 'd52a0c5c-bb7104b0-b1d821a5-959984c3-33c04ccb.tiff', 'Report': 'No acute intrathoracic process. Heart Size is normal. Lungs are clear. No pneumothorax'},
|
43 |
+
"Lateral β Frontal": {'Lateral': 'LtoF.png', 'Frontal': 'FfromL.png'},
|
44 |
+
"Lateral β Report": {'Lateral': 'd52a0c5c-bb7104b0-b1d821a5-959984c3-33c04ccb.tiff', 'Report': 'no acute cardiopulmonary process. if concern for injury persists, a dedicated rib series with markers would be necessary to ensure no rib fractures.'},
|
45 |
+
"Lateral β Frontal + Report": {'Lateral': 'reald52a0c5c-bb7104b0-b1d821a5-959984c3-33c04ccb.tiff', 'Frontal': 'ab37274f-b4c1fc04-e2ff24b4-4a130ba3-cd167968.tiff', 'Report': 'No acute intrathoracic process. If there is strong concern for rib fracture, a dedicated rib series may be performed.'},
|
46 |
+
"Report β Frontal": {'Report': 'Left lung opacification which may reflect pneumonia superimposed on metastatic disease.', 'Frontal': '02aa804e-bde0afdd-112c0b34-7bc16630-4e384014.tiff'},
|
47 |
+
"Report β Lateral": {'Report': 'Bilateral pleural effusions, cardiomegaly and mild edema suggest fluid overload.', 'Lateral': '489faba7-a9dc5f1d-fd7241d6-9638d855-eaa952b1.tiff'},
|
48 |
+
"Report β Frontal + Lateral": {'Report': 'No acute intrathoracic process. The lungs are clean and heart is normal size.', 'Frontal': 'f27ba7cd-44486c2e-29f3e890-f2b9f94e-84110448.tiff', 'Lateral': 'b20c9570-de77944a-b8604ba0-73305a7b-d608a72b.tiff'},
|
49 |
+
"Frontal + Lateral β Report": {'Frontal': '95856dd1-5878b5b1-9c104817-760c0122-6187946f.tiff', 'Lateral': '3723d912-71940d69-4fef2dd2-27af5a7b-127ba20c.tiff', 'Report': 'Opacities in the right upper or middle lobe, maybe early pneumonia.'},
|
50 |
+
"Frontal + Report β Lateral": {'Frontal': 'e7f21453-7956d79a-44e44614-fae8ff16-d174d1a0.tiff', 'Report': 'No focal consolidation.', 'Lateral': '8037e6b9-06367464-a4ccd63a-5c5c5a81-ce3e7ffc.tiff'},
|
51 |
+
"Lateral + Report β Frontal": {'Lateral': '02c66644-b1883a91-54aed0e7-62d25460-398f9865.tiff', 'Report': 'No evidence of acute cardiopulmonary process.', 'Frontal': 'b1f169f1-12177dd5-2fa1c4b1-7b816311-85d769e9.tiff'}
|
52 |
}
|
53 |
|
54 |
|
|
|
158 |
|
159 |
# Immagine con didascalia migliorata e con dimensione della caption aumentata
|
160 |
image_path = "./DEMO/Loghi/model_final.png" # Sostituisci con il percorso della tua immagine
|
161 |
+
st.image(image_path, caption='', use_column_width=True)
|
162 |
|
163 |
# Caption con dimensione del testo migliorata
|
164 |
st.markdown("""
|
|
|
180 |
if st.session_state['step'] == 2:
|
181 |
# Opzioni disponibili
|
182 |
options = [
|
183 |
+
"Frontal β Lateral", "Frontal β Report", "Frontal β Lateral + Report",
|
184 |
+
"Lateral β Frontal", "Lateral β Report", "Lateral β Frontal + Report",
|
185 |
+
"Report β Frontal", "Report β Lateral", "Report β Frontal + Lateral",
|
186 |
+
"Frontal + Lateral β Report", "Frontal + Report β Lateral", "Lateral + Report β Frontal"
|
187 |
]
|
188 |
|
189 |
# Messaggio di selezione con dimensione aumentata
|
|
|
237 |
unsafe_allow_html=True)
|
238 |
|
239 |
# Carica l'immagine frontale
|
240 |
+
if "Frontal" in st.session_state['selected_option'].split(" β")[0]:
|
241 |
st.markdown("<h5 style='font-size: 18px;'>Load the Frontal X-ray in DICOM format</h5>", unsafe_allow_html=True)
|
242 |
st.session_state['frontal_file'] = st.file_uploader("", type=["dcm"])
|
243 |
|
244 |
# Carica l'immagine laterale
|
245 |
+
if "Lateral" in st.session_state['selected_option'].split(" β")[0]:
|
246 |
st.markdown("<h5 style='font-size: 18px;'>Load the Lateral X-ray in DICOM format</h5>", unsafe_allow_html=True)
|
247 |
st.session_state['lateral_file'] = st.file_uploader("", type=["dcm"])
|
248 |
|
249 |
# Inserisci il report clinico
|
250 |
+
if "Report" in st.session_state['selected_option'].split(" β")[0]:
|
251 |
st.markdown("<h5 style='font-size: 18px;'>Type the clinical report</h5>", unsafe_allow_html=True)
|
252 |
st.session_state['report'] = st.text_area("", value=st.session_state['report'])
|
253 |
|
|
|
266 |
with st.spinner("Preprocessing the data..."):
|
267 |
time.sleep(3)
|
268 |
# Controllo che i file necessari siano stati caricati
|
269 |
+
if "Frontal" in st.session_state['selected_option'].split(" β")[0] and not st.session_state['frontal_file']:
|
270 |
st.error("Load the Frontal image.")
|
271 |
+
elif "Lateral" in st.session_state['selected_option'].split(" β")[0] and not st.session_state['lateral_file']:
|
272 |
st.error("Load the Lateral image.")
|
273 |
+
elif "Report" in st.session_state['selected_option'].split(" β")[0] and not st.session_state['report']:
|
274 |
st.error("Type the clinical report.")
|
275 |
else:
|
276 |
st.write(f"Execution of: {st.session_state['selected_option']}")
|
|
|
336 |
st.write(f"Loaded Report: {report}")
|
337 |
|
338 |
inputs = []
|
339 |
+
if "Frontal" in st.session_state['selected_option'].split(" β")[0]:
|
340 |
inputs.append('frontal')
|
341 |
+
if "Lateral" in st.session_state['selected_option'].split(" β")[0]:
|
342 |
inputs.append('lateral')
|
343 |
+
if "Report" in st.session_state['selected_option'].split(" β")[0]:
|
344 |
inputs.append('text')
|
345 |
|
346 |
# Ora vediamo cosa c'Γ¨ dopo la freccia
|
347 |
outputs = []
|
348 |
+
if "Frontal" in st.session_state['selected_option'].split(" β")[1]:
|
349 |
outputs.append('frontal')
|
350 |
+
if "Lateral" in st.session_state['selected_option'].split(" β")[1]:
|
351 |
outputs.append('lateral')
|
352 |
+
if "Report" in st.session_state['selected_option'].split(" β")[1]:
|
353 |
outputs.append('text')
|
354 |
|
355 |
# Ultima cosa che va fatta Γ¨ passare allo step 4, prima di farlo perΓ², tutte le variabili che ci servono
|
|
|
400 |
unsafe_allow_html=True)
|
401 |
|
402 |
inputs = []
|
403 |
+
if "Frontal" in st.session_state['selected_option'].split(" β")[0]:
|
404 |
inputs.append('Frontal')
|
405 |
+
if "Lateral" in st.session_state['selected_option'].split(" β")[0]:
|
406 |
inputs.append('Lateral')
|
407 |
+
if "Report" in st.session_state['selected_option'].split(" β")[0]:
|
408 |
inputs.append('Report')
|
409 |
|
410 |
outputs = []
|
411 |
+
if "Frontal" in st.session_state['selected_option'].split(" β")[1]:
|
412 |
outputs.append('Frontal')
|
413 |
+
if "Lateral" in st.session_state['selected_option'].split(" β")[1]:
|
414 |
outputs.append('Lateral')
|
415 |
+
if "Report" in st.session_state['selected_option'].split(" β")[1]:
|
416 |
outputs.append('Report')
|
417 |
|
418 |
esempio = esempi[st.session_state['selected_option']]
|
419 |
|
420 |
# Mostra i file associati all'esempio
|
421 |
st.markdown(
|
422 |
+
"<h3 style='text-align: center'><strong>INPUT:</strong></h3>",
|
423 |
unsafe_allow_html=True)
|
424 |
|
425 |
# Colonne per gli INPUTS
|
|
|
448 |
st.write(f"Report: {esempio['Report']}")
|
449 |
|
450 |
st.markdown(
|
451 |
+
"<h3 style='text-align: center'><strong>OUTPUT:</strong></h3>",
|
452 |
unsafe_allow_html=True)
|
453 |
|
454 |
# Colonne per gli OUTPUTS
|