vincentgao95 commited on
Commit
edfe705
·
verified ·
1 Parent(s): a5019f4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -8,13 +8,13 @@ from PIL import Image
8
  # Set Matplotlib to use the 'Agg' backend
9
  plt.switch_backend('Agg')
10
 
11
- def load_nrrd(file_path):
12
- data, _ = nrrd.read(file_path.name)
13
  num_slices = data.shape[2]
14
  return data, num_slices
15
 
16
- def visualize_slice(file_path, slice_index):
17
- data, num_slices = load_nrrd(file_path)
18
 
19
  # Ensure the slice index is within the range of available slices
20
  slice_index = min(max(0, slice_index), num_slices - 1)
@@ -35,8 +35,8 @@ def visualize_slice(file_path, slice_index):
35
 
36
  return pil_img
37
 
38
- def update_slider(file_path):
39
- _, num_slices = load_nrrd(file_path)
40
  return gr.update(maximum=num_slices-1, value=0)
41
 
42
  with gr.Blocks() as app:
@@ -51,4 +51,4 @@ with gr.Blocks() as app:
51
  file_input.change(fn=visualize_slice, inputs=[file_input, slider], outputs=image_output)
52
  slider.change(fn=visualize_slice, inputs=[file_input, slider], outputs=image_output)
53
 
54
- app.launch()
 
8
  # Set Matplotlib to use the 'Agg' backend
9
  plt.switch_backend('Agg')
10
 
11
+ def load_nrrd(file_obj):
12
+ data, _ = nrrd.read(file_obj)
13
  num_slices = data.shape[2]
14
  return data, num_slices
15
 
16
+ def visualize_slice(file_obj, slice_index):
17
+ data, num_slices = load_nrrd(file_obj)
18
 
19
  # Ensure the slice index is within the range of available slices
20
  slice_index = min(max(0, slice_index), num_slices - 1)
 
35
 
36
  return pil_img
37
 
38
+ def update_slider(file_obj):
39
+ _, num_slices = load_nrrd(file_obj)
40
  return gr.update(maximum=num_slices-1, value=0)
41
 
42
  with gr.Blocks() as app:
 
51
  file_input.change(fn=visualize_slice, inputs=[file_input, slider], outputs=image_output)
52
  slider.change(fn=visualize_slice, inputs=[file_input, slider], outputs=image_output)
53
 
54
+ app.launch()