Felix-Xu commited on
Commit
3775986
·
1 Parent(s): a5eb38b

example code update

Browse files
Files changed (1) hide show
  1. app.py +21 -6
app.py CHANGED
@@ -17,6 +17,14 @@ from draco.model import (
17
  load_pretrained
18
  )
19
 
 
 
 
 
 
 
 
 
20
  class DRACODenoiser(object):
21
  def __init__(self,
22
  cfg: DictConfig,
@@ -135,7 +143,7 @@ def process_and_denoise(data, x_offset, y_offset, auto_contrast) -> Image:
135
  return denoised_image
136
 
137
  def clear_images() -> tuple:
138
- return None, None, None, gr.update(maximum=512), gr.update(maximum=512)
139
 
140
  with gr.Blocks(css="""
141
  .gradio-container {
@@ -166,12 +174,13 @@ with gr.Blocks(css="""
166
  </div>
167
  """
168
  )
169
-
 
170
  file_input = gr.File(label="Or upload a Micrograph File in .h5 or .mrc format")
171
  auto_contrast = gr.Checkbox(label="Enable Auto Contrast", value=False)
172
 
173
- x_slider = gr.Slider(0, 512, step=10, label="X Offset")
174
- y_slider = gr.Slider(0, 512, step=10, label="Y Offset")
175
 
176
  with gr.Row():
177
  denoise_button = gr.Button("Denoise")
@@ -189,7 +198,13 @@ with gr.Blocks(css="""
189
  data = load_data(file_path)
190
  h, w = data.shape[:2]
191
  return data, gr.update(maximum=w-1024), gr.update(maximum=h-1024)
192
-
 
 
 
 
 
 
193
 
194
  file_input.clear(
195
  clear_images,
@@ -198,7 +213,7 @@ with gr.Blocks(css="""
198
  )
199
 
200
  file_input.change(
201
- lambda file: load_image_and_update_sliders(file.name) if file else (None, None, None, gr.update(maximum=512), gr.update(maximum=512)),
202
  inputs=file_input,
203
  outputs=[active_data, x_slider, y_slider]
204
  )
 
17
  load_pretrained
18
  )
19
 
20
+ example_files = {
21
+ "EMPIAR-10078": "example/empiar-10078-00-000093-full_patch_aligned.h5",
22
+ "EMPIAR-10154": "example/empiar-10154-00-000130-full_patch_aligned.h5",
23
+ "EMPIAR-10185": "example/empiar-10185-00-000032-full_patch_aligned.h5",
24
+ "EMPIAR-10200": "example/empiar-10200-00-000139-full_patch_aligned.h5",
25
+ "EMPIAR-10216": "example/empiar-10216-00-000036-full_patch_aligned.h5"
26
+ }
27
+
28
  class DRACODenoiser(object):
29
  def __init__(self,
30
  cfg: DictConfig,
 
143
  return denoised_image
144
 
145
  def clear_images() -> tuple:
146
+ return None, None, None, gr.update(maximum=1024), gr.update(maximum=1024)
147
 
148
  with gr.Blocks(css="""
149
  .gradio-container {
 
174
  </div>
175
  """
176
  )
177
+
178
+ example_selector = gr.Radio(label="Choose an example Raw Micrograph File", choices=list(example_files.keys()))
179
  file_input = gr.File(label="Or upload a Micrograph File in .h5 or .mrc format")
180
  auto_contrast = gr.Checkbox(label="Enable Auto Contrast", value=False)
181
 
182
+ x_slider = gr.Slider(0, 1024, step=100, label="X Offset")
183
+ y_slider = gr.Slider(0, 1024, step=100, label="Y Offset")
184
 
185
  with gr.Row():
186
  denoise_button = gr.Button("Denoise")
 
198
  data = load_data(file_path)
199
  h, w = data.shape[:2]
200
  return data, gr.update(maximum=w-1024), gr.update(maximum=h-1024)
201
+
202
+
203
+ example_selector.change(
204
+ lambda choice:load_image_and_update_sliders(example_files[choice]),
205
+ inputs=example_selector,
206
+ outputs=[active_data, x_slider, y_slider]
207
+ )
208
 
209
  file_input.clear(
210
  clear_images,
 
213
  )
214
 
215
  file_input.change(
216
+ lambda file: load_image_and_update_sliders(file.name) if file else (None, None, None, gr.update(maximum=1024), gr.update(maximum=1024)),
217
  inputs=file_input,
218
  outputs=[active_data, x_slider, y_slider]
219
  )