SebastianBravo commited on
Commit
d6b54da
1 Parent(s): 80521da

cambios interfaz

Browse files
Files changed (2) hide show
  1. app.py +52 -29
  2. requirements.txt +1 -1
app.py CHANGED
@@ -51,11 +51,14 @@ def load_img(file):
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()
@@ -63,13 +66,15 @@ def show_img(img, mri_slice):
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
 
74
  def clear():
75
  return gr.File.update(value=None), gr.Plot.update(value=None), gr.update(visible=False)
@@ -82,15 +87,9 @@ def clear():
82
  # # outputs='text'
83
  # )
84
 
85
- theme = gr.themes.Base(primary_hue="teal").set(block_background_fill="#235784",)
86
-
87
- css="""
88
- () => {
89
- document.body.classList.toggle('dark', shouldAdd);
90
- }
91
- """
92
 
93
- with gr.Blocks(theme="base", css=css) as demo:
94
  with gr.Row():
95
  # gr.HTML(r"""<center><img src='https://user-images.githubusercontent.com/66338785/233529518-33e8bcdb-146f-49e8-94c4-27d6529ce4f7.png' width="30%" height="30%"></center>""")
96
  gr.HTML(r"""<center><img src='https://user-images.githubusercontent.com/66338785/233531457-f368e04b-5099-42a8-906d-6f1250ea0f1e.png' width="40%" height="40%"></center>""")
@@ -101,22 +100,40 @@ with gr.Blocks(theme="base", css=css) as demo:
101
 
102
  # Inputs
103
  with gr.Row():
104
- with gr.Column(scale=1):
 
105
  with gr.Tab("Personal data"):
106
  # Objeto para subir archivo nifti
107
- input_name = gr.Textbox(placeholder='Ingrese nombre del paciente', label='Name')
108
- input_sex = gr.Dropdown(["Male", "Female"], label="Sex")
109
  input_age = gr.Number(label='Age')
 
 
 
 
110
 
111
  with gr.Tab("Clinical data"):
112
  input_MMSE = gr.Number(label='MMSE')
113
  input_GDSCALE = gr.Number(label='GDSCALE')
114
  input_CDR = gr.Number(label='Global CDR')
115
  input_FAQ = gr.Number(label='FAQ Total Score')
116
- input_NPI_Q = gr.Number(label='NPI-Q Total Score')
117
-
118
- input_file = gr.File(file_count="single", file_type=[".nii"], label="Archivo Imagen MRI")
119
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  with gr.Row():
121
  # Bot贸n para cargar imagen
122
  load_img_button = gr.Button(value="Load")
@@ -125,10 +142,12 @@ with gr.Blocks(theme="base", css=css) as demo:
125
  clear_button = gr.Button(value="Clear")
126
 
127
  # Bot贸n para procesar imagen
128
- process_button = gr.Button(value="Procesar")
129
 
130
  # Outputs
131
- with gr.Column(scale=1):
 
 
132
  # Plot para im谩gen original
133
  plot_img_original = gr.Plot(label="Imagen MRI original")
134
 
@@ -141,7 +160,7 @@ with gr.Blocks(theme="base", css=css) as demo:
141
  visible=False)
142
 
143
  # Plot para im谩gen procesada
144
- plot_brain = gr.Plot(label="Imagen MRI procesada")
145
 
146
  # Slider para im谩gen procesada
147
  brain_slider = gr.Slider(minimum=0,
@@ -158,16 +177,19 @@ with gr.Blocks(theme="base", css=css) as demo:
158
  original_input_img = gr.State()
159
  brain_img = gr.State()
160
 
 
 
 
161
  # Cambios
162
  # Cargar imagen nueva
163
  input_file.change(load_img,
164
  input_file,
165
- [original_input_sitk, original_input_img],)
166
 
167
  # Mostrar imagen nueva
168
  load_img_button.click(show_img,
169
- [original_input_img, mri_slider],
170
- [plot_img_original, mri_slider])
171
 
172
  # Limpiar campos
173
  clear_button.click(fn=clear,
@@ -175,8 +197,8 @@ with gr.Blocks(theme="base", css=css) as demo:
175
 
176
  # Actualizar imagen original
177
  mri_slider.change(show_img,
178
- [original_input_img, mri_slider],
179
- [plot_img_original,mri_slider])
180
 
181
  # Procesar imagen
182
  process_button.click(fn=process_img,
@@ -185,11 +207,12 @@ with gr.Blocks(theme="base", css=css) as demo:
185
 
186
  # Actualizar imagen procesada
187
  brain_slider.change(show_img,
188
- [brain_img, brain_slider],
189
- [plot_brain,brain_slider])
190
 
191
 
192
  if __name__ == "__main__":
 
193
  demo.launch()
194
 
195
  # # Visualizaci贸n resultados
 
51
 
52
  return sitk, mri_image
53
 
54
+ def show_img(img, mri_slice, update):
55
  fig = plt.figure()
56
  plt.imshow(img[mri_slice,:,:], cmap='gray')
57
 
58
+ if update == True:
59
+ return fig, gr.update(visible=True), gr.update(visible=True)
60
+ else:
61
+ return fig
62
 
63
  # def show_brain(brain, brain_slice):
64
  # fig = plt.figure()
 
66
 
67
  # return fig, gr.update(visible=True)
68
 
69
+ def process_img(img, brain_slice, progress=gr.Progress()):
70
+ progress(880,desc="Processing...")
71
+
72
  with tf.device("cpu:0"):
73
  brain = utils.brain_stripping(img, model_unet)
74
 
75
+ fig, update_slider, _ = show_img(brain, brain_slice, update=True)
76
 
77
+ return brain, fig, update_slider
78
 
79
  def clear():
80
  return gr.File.update(value=None), gr.Plot.update(value=None), gr.update(visible=False)
 
87
  # # outputs='text'
88
  # )
89
 
90
+ # theme = gr.themes.Base().load('css_new.json')
 
 
 
 
 
 
91
 
92
+ with gr.Blocks(theme=gr.themes.Base()) as demo:
93
  with gr.Row():
94
  # gr.HTML(r"""<center><img src='https://user-images.githubusercontent.com/66338785/233529518-33e8bcdb-146f-49e8-94c4-27d6529ce4f7.png' width="30%" height="30%"></center>""")
95
  gr.HTML(r"""<center><img src='https://user-images.githubusercontent.com/66338785/233531457-f368e04b-5099-42a8-906d-6f1250ea0f1e.png' width="40%" height="40%"></center>""")
 
100
 
101
  # Inputs
102
  with gr.Row():
103
+ with gr.Column(variant="panel", scale=1):
104
+ gr.Markdown('<h2 style="text-align: center; color:#235784;">Patient Information</h2>')
105
  with gr.Tab("Personal data"):
106
  # Objeto para subir archivo nifti
107
+ input_name = gr.Textbox(placeholder='Enter the patient name', label='Patient name')
 
108
  input_age = gr.Number(label='Age')
109
+ input_phone_num = gr.Number(label='Phone number')
110
+ input_emer_name = gr.Textbox(placeholder='Enter the emergency contact name', label='Emergency contact name')
111
+ input_emer_phone_num = gr.Number(label='Emergency contact name phone number')
112
+ input_sex = gr.Dropdown(["Male", "Female"], label="Sex")
113
 
114
  with gr.Tab("Clinical data"):
115
  input_MMSE = gr.Number(label='MMSE')
116
  input_GDSCALE = gr.Number(label='GDSCALE')
117
  input_CDR = gr.Number(label='Global CDR')
118
  input_FAQ = gr.Number(label='FAQ Total Score')
119
+ input_NPI_Q = gr.Number(label='NPI-Q Total Score')
 
 
120
 
121
+ with gr.Tab("Vital Signs"):
122
+ input_Diastolic_blood_pressure = gr.Number(label='Diastolic Blood Pressure(mm Hg)')
123
+ input_Systolic_blood_pressure = gr.Number(label='Systolic Blood Pressure(mm Hg)')
124
+ input_Body_heigth = gr.Number(label='Body heigth (cm)')
125
+ input_Body_weight = gr.Number(label='Body weigth (kg)')
126
+ input_Heart_rate = gr.Number(label='Heart rate (bpm)')
127
+ input_Respiratory_rate = gr.Number(label='Respiratory rate (bpm)')
128
+ input_Body_temperature = gr.Number(label='Body temperature (掳C)')
129
+ input_Pluse_oximetry = gr.Number(label='Pluse oximetry (%)')
130
+
131
+ with gr.Tab("Medications"):
132
+ input_medications = gr.Textbox(label='Medications', lines=5)
133
+ input_allergies = gr.Textbox(label='Allergies', lines=5)
134
+
135
+ input_file = gr.File(file_count="single", label="MRI Image File (.nii)")
136
+
137
  with gr.Row():
138
  # Bot贸n para cargar imagen
139
  load_img_button = gr.Button(value="Load")
 
142
  clear_button = gr.Button(value="Clear")
143
 
144
  # Bot贸n para procesar imagen
145
+ process_button = gr.Button(value="Procesar", visible=False)
146
 
147
  # Outputs
148
+ with gr.Column(variant="panel", scale=1):
149
+ gr.Markdown('<h2 style="text-align: center; color:#235784;">MRI visualization</h2>')
150
+
151
  # Plot para im谩gen original
152
  plot_img_original = gr.Plot(label="Imagen MRI original")
153
 
 
160
  visible=False)
161
 
162
  # Plot para im谩gen procesada
163
+ plot_brain = gr.Plot(label="Imagen MRI procesada", visible=True)
164
 
165
  # Slider para im谩gen procesada
166
  brain_slider = gr.Slider(minimum=0,
 
177
  original_input_img = gr.State()
178
  brain_img = gr.State()
179
 
180
+ update_true = gr.State(True)
181
+ update_false = gr.State(False)
182
+
183
  # Cambios
184
  # Cargar imagen nueva
185
  input_file.change(load_img,
186
  input_file,
187
+ [original_input_sitk, original_input_img])
188
 
189
  # Mostrar imagen nueva
190
  load_img_button.click(show_img,
191
+ [original_input_img, mri_slider, update_true],
192
+ [plot_img_original, mri_slider, process_button])
193
 
194
  # Limpiar campos
195
  clear_button.click(fn=clear,
 
197
 
198
  # Actualizar imagen original
199
  mri_slider.change(show_img,
200
+ [original_input_img, mri_slider, update_false],
201
+ [plot_img_original])
202
 
203
  # Procesar imagen
204
  process_button.click(fn=process_img,
 
207
 
208
  # Actualizar imagen procesada
209
  brain_slider.change(show_img,
210
+ [brain_img, brain_slider, update_false],
211
+ [plot_brain])
212
 
213
 
214
  if __name__ == "__main__":
215
+ demo.queue(concurrency_count=20)
216
  demo.launch()
217
 
218
  # # Visualizaci贸n resultados
requirements.txt CHANGED
@@ -1,4 +1,4 @@
1
- gradio==3.27.0
2
  keras==2.10.0
3
  matplotlib==3.5.2
4
  numpy==1.21.5
 
1
+ gradio==3.28.3
2
  keras==2.10.0
3
  matplotlib==3.5.2
4
  numpy==1.21.5