Spaces:
Paused
Paused
Commit
路
3a7ffad
1
Parent(s):
610d625
More scores and logo
Browse files- Header.png +0 -0
- Header.svg +0 -16
- Header2.png +0 -0
- app.py +48 -25
Header.png
CHANGED
![]() |
![]() |
Header.svg
DELETED
Header2.png
ADDED
![]() |
app.py
CHANGED
@@ -1,4 +1,6 @@
|
|
|
|
1 |
import utils
|
|
|
2 |
import gradio as gr
|
3 |
import tensorflow as tf
|
4 |
import matplotlib.pyplot as plt
|
@@ -7,9 +9,12 @@ from urllib.request import urlretrieve
|
|
7 |
|
8 |
# '''--------------------------- Preprocesamiento ----------------------------'''
|
9 |
# tic()
|
10 |
-
# 3D U-Net
|
11 |
-
|
12 |
-
urlretrieve("https://dl.dropboxusercontent.com/s/
|
|
|
|
|
|
|
13 |
|
14 |
path_3d_unet = 'unet.h5'
|
15 |
|
@@ -34,26 +39,35 @@ with tf.device("cpu:0"):
|
|
34 |
# features = utils.get_features(brain, mednet)
|
35 |
|
36 |
def load_img(file):
|
37 |
-
sitk, array = utils.load_img(file.name)
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
def show_img(img, mri_slice):
|
41 |
fig = plt.figure()
|
42 |
-
plt.imshow(img[
|
43 |
|
44 |
return fig, gr.update(visible=True)
|
45 |
|
46 |
-
def show_brain(brain, brain_slice):
|
47 |
-
|
48 |
-
|
49 |
|
50 |
-
|
51 |
|
52 |
def process_img(img, brain_slice):
|
53 |
with tf.device("cpu:0"):
|
54 |
brain = utils.brain_stripping(img, model_unet)
|
55 |
|
56 |
-
fig, update =
|
57 |
|
58 |
return brain, fig, update
|
59 |
|
@@ -68,21 +82,30 @@ def clear():
|
|
68 |
# # outputs='text'
|
69 |
# )
|
70 |
|
71 |
-
with gr.Blocks() as demo:
|
72 |
with gr.Row():
|
73 |
-
gr.
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
|
|
78 |
|
79 |
# Inputs
|
80 |
with gr.Row():
|
81 |
-
with gr.Column(scale=1):
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
|
87 |
input_file = gr.File(file_count="single", file_type=[".nii"], label="Archivo Imagen MRI")
|
88 |
|
@@ -103,12 +126,12 @@ with gr.Blocks() as demo:
|
|
103 |
|
104 |
# Slider para im谩gen original
|
105 |
mri_slider = gr.Slider(minimum=0,
|
106 |
-
maximum=
|
107 |
value=100,
|
108 |
step=1,
|
109 |
label="MRI Slice",
|
110 |
visible=False)
|
111 |
-
|
112 |
# Plot para im谩gen procesada
|
113 |
plot_brain = gr.Plot(label="Imagen MRI procesada")
|
114 |
|
@@ -153,7 +176,7 @@ with gr.Blocks() as demo:
|
|
153 |
outputs=[brain_img,plot_brain,brain_slider])
|
154 |
|
155 |
# Actualizar imagen procesada
|
156 |
-
brain_slider.change(
|
157 |
[brain_img, brain_slider],
|
158 |
[plot_brain,brain_slider])
|
159 |
|
|
|
1 |
+
import os
|
2 |
import utils
|
3 |
+
import numpy as np
|
4 |
import gradio as gr
|
5 |
import tensorflow as tf
|
6 |
import matplotlib.pyplot as plt
|
|
|
9 |
|
10 |
# '''--------------------------- Preprocesamiento ----------------------------'''
|
11 |
# tic()
|
12 |
+
# 3D U-Net\
|
13 |
+
if not os.path.exists("unet.h5"):
|
14 |
+
urlretrieve("https://dl.dropboxusercontent.com/s/ay5q8caqzlad7h5/unet.h5?dl=0", "unet.h5")
|
15 |
+
|
16 |
+
if not os.path.exists("resnet_50_23dataset.pth"):
|
17 |
+
urlretrieve("https://dl.dropboxusercontent.com/s/otxsgx3e31d5h9i/resnet_50_23dataset.pth?dl=0", "resnet_50_23dataset.pth")
|
18 |
|
19 |
path_3d_unet = 'unet.h5'
|
20 |
|
|
|
39 |
# features = utils.get_features(brain, mednet)
|
40 |
|
41 |
def load_img(file):
|
42 |
+
sitk, array = utils.load_img(file.name)
|
43 |
+
|
44 |
+
# Redimenci贸n
|
45 |
+
mri_image = np.transpose(array)
|
46 |
+
mri_image = np.append(mri_image, np.zeros((192-mri_image.shape[0],256,256,)), axis=0)
|
47 |
+
|
48 |
+
# Rotaci贸n
|
49 |
+
mri_image = mri_image.astype(np.float32)
|
50 |
+
mri_image = np.rot90(mri_image, axes=(1,2))
|
51 |
+
|
52 |
+
return sitk, mri_image
|
53 |
|
54 |
def show_img(img, mri_slice):
|
55 |
fig = plt.figure()
|
56 |
+
plt.imshow(img[mri_slice,:,:], cmap='gray')
|
57 |
|
58 |
return fig, gr.update(visible=True)
|
59 |
|
60 |
+
# def show_brain(brain, brain_slice):
|
61 |
+
# fig = plt.figure()
|
62 |
+
# plt.imshow(brain[brain_slice,:,:], cmap='gray')
|
63 |
|
64 |
+
# return fig, gr.update(visible=True)
|
65 |
|
66 |
def process_img(img, brain_slice):
|
67 |
with tf.device("cpu:0"):
|
68 |
brain = utils.brain_stripping(img, model_unet)
|
69 |
|
70 |
+
fig, update = show_img(brain, brain_slice)
|
71 |
|
72 |
return brain, fig, update
|
73 |
|
|
|
82 |
# # outputs='text'
|
83 |
# )
|
84 |
|
85 |
+
with gr.Blocks(theme=gr.themes.Base(primary_hue="teal")) as demo:
|
86 |
with gr.Row():
|
87 |
+
# gr.HTML(r"""<center><img src='https://user-images.githubusercontent.com/66338785/233529518-33e8bcdb-146f-49e8-94c4-27d6529ce4f7.png' width="30%" height="30%"></center>""")
|
88 |
+
gr.HTML(r"""<center><img src='https://user-images.githubusercontent.com/66338785/233531457-f368e04b-5099-42a8-906d-6f1250ea0f1e.png' width="40%" height="40%"></center>""")
|
89 |
+
# gr.Markdown("""
|
90 |
+
# # SIMCI
|
91 |
+
# Interfaz de SIMCI
|
92 |
+
# """)
|
93 |
|
94 |
# Inputs
|
95 |
with gr.Row():
|
96 |
+
with gr.Column(scale=1):
|
97 |
+
with gr.Tab("Personal data"):
|
98 |
+
# Objeto para subir archivo nifti
|
99 |
+
input_name = gr.Textbox(placeholder='Ingrese nombre del paciente', label='Name')
|
100 |
+
input_sex = gr.Dropdown(["Male", "Female"], label="Sex")
|
101 |
+
input_age = gr.Number(label='Age')
|
102 |
+
|
103 |
+
with gr.Tab("Clinical data"):
|
104 |
+
input_MMSE = gr.Number(label='MMSE')
|
105 |
+
input_GDSCALE = gr.Number(label='GDSCALE')
|
106 |
+
input_CDR = gr.Number(label='Global CDR')
|
107 |
+
input_FAQ = gr.Number(label='FAQ Total Score')
|
108 |
+
input_NPI_Q = gr.Number(label='NPI-Q Total Score')
|
109 |
|
110 |
input_file = gr.File(file_count="single", file_type=[".nii"], label="Archivo Imagen MRI")
|
111 |
|
|
|
126 |
|
127 |
# Slider para im谩gen original
|
128 |
mri_slider = gr.Slider(minimum=0,
|
129 |
+
maximum=192,
|
130 |
value=100,
|
131 |
step=1,
|
132 |
label="MRI Slice",
|
133 |
visible=False)
|
134 |
+
|
135 |
# Plot para im谩gen procesada
|
136 |
plot_brain = gr.Plot(label="Imagen MRI procesada")
|
137 |
|
|
|
176 |
outputs=[brain_img,plot_brain,brain_slider])
|
177 |
|
178 |
# Actualizar imagen procesada
|
179 |
+
brain_slider.change(show_img,
|
180 |
[brain_img, brain_slider],
|
181 |
[plot_brain,brain_slider])
|
182 |
|