osbm commited on
Commit
2e39630
1 Parent(s): a5bdd49
Files changed (1) hide show
  1. app.py +7 -11
app.py CHANGED
@@ -1,16 +1,13 @@
1
  import gradio as gr
2
- import nibabel as nib
3
- import pydicom
4
  import os
5
  import dicom2nifti
6
 
7
  def convert(input):
8
- # if linux
9
  path = input.name
10
  print("Zip file path:", path)
11
-
12
  assert path.endswith('.zip'), 'File must be a zip file'
13
-
14
  os.system(f'unzip -q "{path}" -d "{path[:-4]}"')
15
  path = path[:-4]
16
  files = os.listdir(path)
@@ -19,19 +16,18 @@ def convert(input):
19
  print("Dicom folder path:", path)
20
  dicom_files = os.listdir(path)
21
  assert [f.endswith('.dcm') for f in dicom_files], 'Dicom folder must contain only .dcm files'
22
-
23
- print("This is the list of files in the folder:", os.listdir(path))
24
- # create an output file that has the same name as the input file but with a .nii.gz extension
25
  output_file = os.path.join(path, os.path.basename(path) + '.nii.gz')
26
  dicom2nifti.dicom_series_to_nifti(path, output_file, reorient_nifti=True)
27
  print("Nifti file path:", output_file)
28
-
29
  return output_file
30
 
31
 
32
- gr.Interface(
33
  fn=convert,
34
  inputs=gr.File(type="file", label="Dicom folder (.zip)", file_types=["zip"]),
35
  outputs="file",
36
  title="Convert a Dicom folder to a Nifti (.nii.gz) file",
37
- ).launch()
 
 
 
1
  import gradio as gr
2
+ # import nibabel as nib
3
+ # import pydicom
4
  import os
5
  import dicom2nifti
6
 
7
  def convert(input):
 
8
  path = input.name
9
  print("Zip file path:", path)
 
10
  assert path.endswith('.zip'), 'File must be a zip file'
 
11
  os.system(f'unzip -q "{path}" -d "{path[:-4]}"')
12
  path = path[:-4]
13
  files = os.listdir(path)
 
16
  print("Dicom folder path:", path)
17
  dicom_files = os.listdir(path)
18
  assert [f.endswith('.dcm') for f in dicom_files], 'Dicom folder must contain only .dcm files'
19
+
 
 
20
  output_file = os.path.join(path, os.path.basename(path) + '.nii.gz')
21
  dicom2nifti.dicom_series_to_nifti(path, output_file, reorient_nifti=True)
22
  print("Nifti file path:", output_file)
 
23
  return output_file
24
 
25
 
26
+ app = gr.Interface(
27
  fn=convert,
28
  inputs=gr.File(type="file", label="Dicom folder (.zip)", file_types=["zip"]),
29
  outputs="file",
30
  title="Convert a Dicom folder to a Nifti (.nii.gz) file",
31
+ )
32
+ app.queue(concurrency_count=1)
33
+ app.launch()