Spaces:
Runtime error
Runtime error
Commit
·
a345f02
1
Parent(s):
9cbbb9b
Update app.py
Browse files
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
|
6 |
-
#
|
7 |
-
|
8 |
-
|
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 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
)
|
43 |
|
44 |
-
|
|
|
|
|
|
|
|
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()
|