FrancescoLR commited on
Commit
7801205
·
1 Parent(s): 73146f8

First commit

Browse files
Files changed (3) hide show
  1. README.md +1 -14
  2. app.py +59 -0
  3. requirements.txt +5 -0
README.md CHANGED
@@ -1,14 +1 @@
1
- ---
2
- title: FLAMeS
3
- emoji: 🏃
4
- colorFrom: blue
5
- colorTo: red
6
- sdk: gradio
7
- sdk_version: 5.9.1
8
- app_file: app.py
9
- pinned: false
10
- license: gpl-3.0
11
- short_description: Automated segmentation of MS lesions
12
- ---
13
-
14
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+ Tool for the automated segmentation of multiple sclerosis lesions from diverse FLAIR scans.
 
 
 
 
 
 
 
 
 
 
 
 
 
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import subprocess
3
+ import os
4
+ import shutil
5
+
6
+ # Paths
7
+ INPUT_DIR = "/tmp/input"
8
+ OUTPUT_DIR = "/tmp/output"
9
+ MODEL_DIR = "./model"
10
+
11
+ def run_nnunet_predict(nifti_file):
12
+ # Prepare directories
13
+ os.makedirs(INPUT_DIR, exist_ok=True)
14
+ os.makedirs(OUTPUT_DIR, exist_ok=True)
15
+
16
+ # Save the uploaded file to the input directory
17
+ input_path = os.path.join(INPUT_DIR, "image.nii.gz")
18
+ shutil.copy(nifti_file.name, input_path)
19
+
20
+ # Set environment variables for nnUNet
21
+ os.environ["nnUNet_raw"] = MODEL_DIR
22
+ os.environ["nnUNet_preprocessed"] = MODEL_DIR
23
+ os.environ["nnUNet_results"] = MODEL_DIR
24
+
25
+ # Construct the nnUNetv2_predict command
26
+ command = [
27
+ "nnUNetv2_predict",
28
+ "-i", INPUT_DIR,
29
+ "-o", OUTPUT_DIR,
30
+ "-d", "004", # Dataset ID
31
+ "-c", "3d_fullres", # Configuration
32
+ "-tr", "nnUNetTrainer_8000epochs", # Trainer name
33
+ ]
34
+
35
+ # Run the command
36
+ try:
37
+ subprocess.run(command, check=True)
38
+ # Get the output file
39
+ output_file = os.path.join(OUTPUT_DIR, "image.nii.gz")
40
+ return output_file
41
+ except subprocess.CalledProcessError as e:
42
+ return f"Error: {e}"
43
+
44
+ # Gradio Interface
45
+ interface = gr.Interface(
46
+ fn=run_nnunet_predict,
47
+ inputs=gr.File(label="Upload FLAIR Image (.nii.gz)"),
48
+ outputs=gr.File(label="Download Segmentation Mask"),
49
+ title="FLAMeS: FLAIR Lesion Analysis in Multiple Sclerosis",
50
+ description=(
51
+ "Upload a skull-stripped FLAIR image (.nii.gz) to generate a binary segmentation of MS lesions. "
52
+ "This model uses nnUNetv2 for inference with ensemble predictions."
53
+ ),
54
+ )
55
+
56
+ # Launch the app
57
+ if __name__ == "__main__":
58
+ interface.launch()
59
+
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ gradio
2
+ torch
3
+ nnunetv2
4
+ nibabel
5
+ numpy