sumit-ai-ml commited on
Commit
460fece
·
1 Parent(s): 9cbbb9b
Files changed (1) hide show
  1. app.py +16 -39
app.py CHANGED
@@ -1,44 +1,21 @@
1
- import nibabel as nib
2
- import matplotlib.pyplot as plt
3
  import gradio as gr
 
 
4
 
5
- def visualize_nii_gz(file_path):
6
- # Load the NIfTI file
7
- img = nib.load(file_path.name)
8
- data = img.get_fdata()
9
-
10
- # Get the middle slice of the data in all three dimensions
11
- x_slice = data[data.shape[0] // 2, :, :]
12
- y_slice = data[:, data.shape[1] // 2, :]
13
- z_slice = data[:, :, data.shape[2] // 2]
14
-
15
- # Plot the slices
16
- fig = plt.figure(figsize=(12, 4))
17
-
18
- ax1 = fig.add_subplot(131)
19
- ax1.imshow(x_slice.T, cmap="gray", origin="lower")
20
- ax1.set_title("X slice")
21
-
22
- ax2 = fig.add_subplot(132)
23
- ax2.imshow(y_slice.T, cmap="gray", origin="lower")
24
- ax2.set_title("Y slice")
25
-
26
- ax3 = fig.add_subplot(133)
27
- ax3.imshow(z_slice.T, cmap="gray", origin="lower")
28
- ax3.set_title("Z slice")
29
-
30
- # Return the figure
31
- plt.tight_layout()
32
- return fig
33
 
34
- # Create the Gradio interface
35
- interface = gr.Interface(
36
- fn=visualize_nii_gz,
37
- inputs="file",
38
- outputs="plot",
39
- live=True,
40
- title="3D NIfTI Visualizer",
41
- description="Upload a .nii.gz file to visualize its slices in 3D."
42
  )
43
 
44
- interface.launch()
 
 
 
 
1
  import gradio as gr
2
+ import nibabel as nib # For handling .nii or .nii.gz files
3
+ import os
4
 
5
+ def convert_and_load_mesh(nii_file_path):
6
+ # Assume convert_to_obj is a function that converts .nii/.nii.gz to .obj
7
+ obj_file_path = convert_to_obj(nii_file_path)
8
+ return obj_file_path
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
+ def convert_to_obj(nii_file_path):
11
+ # Conversion logic here
12
+ pass
13
+
14
+ demo = gr.Interface(
15
+ fn=convert_and_load_mesh,
16
+ inputs=gr.Model3D(),
17
+ outputs=gr.Model3D(clear_color=[0.0, 0.0, 0.0, 0.0], label="3D Model"),
18
  )
19
 
20
+ if __name__ == "__main__":
21
+ demo.launch()