FrancescoLR commited on
Commit
a581467
·
verified ·
1 Parent(s): 4038cea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -0
app.py CHANGED
@@ -165,6 +165,21 @@ def run_nnunet_predict(nifti_file):
165
  input_path = os.path.join(INPUT_DIR, "image_0000.nii.gz")
166
  os.rename(nifti_file.name, input_path) # Move the uploaded file to the expected input location
167
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  # Debugging: List files in the /tmp/input directory
169
  print("Files in /tmp/input:")
170
  print(os.listdir(INPUT_DIR))
 
165
  input_path = os.path.join(INPUT_DIR, "image_0000.nii.gz")
166
  os.rename(nifti_file.name, input_path) # Move the uploaded file to the expected input location
167
 
168
+ # Apply skull-stripping with HD-BET
169
+ hd_bet_output_path = os.path.join(INPUT_DIR, "image_0000_stripped.nii.gz")
170
+ try:
171
+ subprocess.run([
172
+ "hd-bet",
173
+ "-i", input_path,
174
+ "-o", hd_bet_output_path,
175
+ "-device", "cpu", # or "cuda" if available
176
+ "-mode", "fast"
177
+ ], check=True)
178
+ print("Skull-stripping completed.")
179
+ input_path = hd_bet_output_path
180
+ except subprocess.CalledProcessError as e:
181
+ return f"HD-BET Error: {e}"
182
+
183
  # Debugging: List files in the /tmp/input directory
184
  print("Files in /tmp/input:")
185
  print(os.listdir(INPUT_DIR))