IFMedTechdemo commited on
Commit
a8e2b25
·
verified ·
1 Parent(s): b64c598

Add initial NIfTI viewer app with basic file upload and info display

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import nibabel as nib
3
+ import numpy as np
4
+
5
+ def process_nifti(file):
6
+ if file is None:
7
+ return "No file uploaded."
8
+
9
+ try:
10
+ # Load the NIfTI file
11
+ img = nib.load(file.name)
12
+
13
+ # Get basic information
14
+ shape = img.shape
15
+ data_type = img.get_data_dtype()
16
+ header = img.header
17
+
18
+ # Create a summary
19
+ info = f"""File successfully loaded!
20
+
21
+ Shape: {shape}
22
+ Data type: {data_type}
23
+ Dimensions: {len(shape)}D
24
+ Voxel dimensions: {header.get_zooms()}
25
+ """
26
+
27
+ return info
28
+ except Exception as e:
29
+ return f"Error loading file: {str(e)}"
30
+
31
+ # Create Gradio interface
32
+ demo = gr.Interface(
33
+ fn=process_nifti,
34
+ inputs=gr.File(label="Upload NIfTI file (.nii or .nii.gz)"),
35
+ outputs=gr.Textbox(label="File Information", lines=10),
36
+ title="NIfTI File Viewer",
37
+ description="Upload a NIfTI (.nii or .nii.gz) file to view basic information about it."
38
+ )
39
+
40
+ if __name__ == "__main__":
41
+ demo.launch()