FrancescoLR commited on
Commit
699652d
·
verified ·
1 Parent(s): 60721af

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -16
app.py CHANGED
@@ -172,7 +172,7 @@ def extract_middle_slices(nifti_path, output_image_path, slice_size=180, center=
172
 
173
  # Function to run nnUNet inference
174
  @spaces.GPU(duration=90) # Decorate the function to allocate GPU for its execution
175
- def run_nnunet_predict(nifti_file):
176
  # Prepare directories
177
  os.makedirs(INPUT_DIR, exist_ok=True)
178
  os.makedirs(OUTPUT_DIR, exist_ok=True)
@@ -184,21 +184,21 @@ def run_nnunet_predict(nifti_file):
184
  # Save the uploaded file to the input directory
185
  input_path = os.path.join(INPUT_DIR, "image_0000.nii.gz")
186
  os.rename(nifti_file.name, input_path) # Move the uploaded file to the expected input location
187
-
188
- # Apply skull-stripping with HD-BET
189
- hd_bet_output_path = os.path.join(INPUT_DIR, "image_0000.nii.gz")
190
- try:
191
- subprocess.run([
192
- "hd-bet",
193
- "-i", input_path,
194
- "-o", hd_bet_output_path,
195
- "-device", "cuda", # or "cpu"
196
- "--disable_tta"
197
- ], check=True)
198
- print("Skull-stripping completed.")
199
- input_path = hd_bet_output_path
200
- except subprocess.CalledProcessError as e:
201
- return f"HD-BET Error: {e}"
202
 
203
  # Debugging: List files in the /tmp/input directory
204
  print("Files in /tmp/input:")
@@ -268,6 +268,7 @@ with gr.Blocks() as demo:
268
  with gr.Row():
269
  with gr.Column(scale=1):
270
  flair_input = gr.File(label="Upload a FLAIR Image (.nii.gz)")
 
271
  submit_button = gr.Button("Submit")
272
  with gr.Column(scale=2):
273
  seg_output = gr.File(label="Download the Lesion Segmentation Mask")
 
172
 
173
  # Function to run nnUNet inference
174
  @spaces.GPU(duration=90) # Decorate the function to allocate GPU for its execution
175
+ def run_nnunet_predict(nifti_file,hd_bet=False):
176
  # Prepare directories
177
  os.makedirs(INPUT_DIR, exist_ok=True)
178
  os.makedirs(OUTPUT_DIR, exist_ok=True)
 
184
  # Save the uploaded file to the input directory
185
  input_path = os.path.join(INPUT_DIR, "image_0000.nii.gz")
186
  os.rename(nifti_file.name, input_path) # Move the uploaded file to the expected input location
187
+
188
+ if hd_bet:
189
+ # Apply skull-stripping with HD-BET
190
+ hd_bet_output_path = os.path.join(INPUT_DIR, "image_0000.nii.gz")
191
+ try:
192
+ subprocess.run([
193
+ "hd-bet",
194
+ "-i", input_path,
195
+ "-o", hd_bet_output_path,
196
+ "-device", "cuda", # or "cpu"
197
+ "--disable_tta" ], check=True)
198
+ print("Skull-stripping completed.")
199
+ input_path = hd_bet_output_path
200
+ except subprocess.CalledProcessError as e:
201
+ return f"HD-BET Error: {e}"
202
 
203
  # Debugging: List files in the /tmp/input directory
204
  print("Files in /tmp/input:")
 
268
  with gr.Row():
269
  with gr.Column(scale=1):
270
  flair_input = gr.File(label="Upload a FLAIR Image (.nii.gz)")
271
+ use_hd_bet = gr.Checkbox(label="Apply skull-stripping", value=False)
272
  submit_button = gr.Button("Submit")
273
  with gr.Column(scale=2):
274
  seg_output = gr.File(label="Download the Lesion Segmentation Mask")