Spaces:
Running
on
Zero
Running
on
Zero
FrancescoLR
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -214,63 +214,38 @@ def run_nnunet_predict(nifti_file):
|
|
214 |
except subprocess.CalledProcessError as e:
|
215 |
return f"Error: {e}"
|
216 |
|
217 |
-
#
|
218 |
-
interface = gr.Interface(
|
219 |
-
fn=run_nnunet_predict,
|
220 |
-
inputs=[
|
221 |
-
gr.File(label="Upload FLAIR Image (.nii.gz)")
|
222 |
-
],
|
223 |
-
outputs=[
|
224 |
-
gr.File(label="Download Segmentation Mask"),
|
225 |
-
gr.Image(label="Input: FLAIR image"),
|
226 |
-
gr.Image(label="Output: Lesion Mask")
|
227 |
-
],
|
228 |
-
title="FLAMeS: Multiple Sclerosis Lesion Segmentation",
|
229 |
-
description="Upload a skull-stripped FLAIR image (.nii.gz) to generate a binary segmentation of multiple sclerosis lesions.",
|
230 |
-
)
|
231 |
-
|
232 |
-
# Markdown content as a string
|
233 |
-
# Markdown content as a string
|
234 |
-
markdown_content = """
|
235 |
-
**If you find this tool useful, please consider citing:**
|
236 |
-
|
237 |
-
1. A Deep Learning-Based Pipeline for Longitudinal White Matter Lesion Segmentation Using Diverse FLAIR Images
|
238 |
-
F. La Rosa, J. Dos Santos Silva, W. A. Mullins, H. Greenspan, J. F. Sumowski, D. S. Reich, & E. S. Beck.
|
239 |
-
*ACTRIMS Forum 2023 - Poster Presentations. Multiple Sclerosis Journal.* 2023;29(2_suppl):18-242.
|
240 |
-
DOI: [10.1177/13524585231169437](https://doi.org/10.1177/13524585231169437)
|
241 |
-
|
242 |
-
2. nnU-Net: A Self-Configuring Method for Deep Learning-Based Biomedical Image Segmentation
|
243 |
-
F. Isensee, P. F. Jaeger, S. A. Kohl, J. Petersen, & K. H. Maier-Hein.
|
244 |
-
*Nature Methods.* 2021;18(2):203-211.
|
245 |
-
DOI: [10.1038/s41592-020-01008-z](https://www.nature.com/articles/s41592-020-01008-z)
|
246 |
-
"""
|
247 |
-
|
248 |
-
# Use Gradio Blocks for a clean layout
|
249 |
with gr.Blocks() as demo:
|
250 |
-
# Title and Description
|
251 |
gr.Markdown("""
|
252 |
# FLAMeS: Multiple Sclerosis Lesion Segmentation
|
253 |
|
254 |
Upload a skull-stripped FLAIR image (.nii.gz) to generate a binary segmentation of multiple sclerosis lesions.
|
255 |
""")
|
256 |
-
|
257 |
-
# Layout for Inputs and Outputs
|
258 |
with gr.Row():
|
259 |
-
with gr.Column(scale=1):
|
260 |
flair_input = gr.File(label="Upload FLAIR Image (.nii.gz)")
|
261 |
submit_button = gr.Button("Submit")
|
262 |
-
with gr.Column(scale=2):
|
263 |
seg_output = gr.File(label="Download Segmentation Mask")
|
264 |
input_img = gr.Image(label="Input: FLAIR image")
|
265 |
output_img = gr.Image(label="Output: Lesion Mask")
|
266 |
-
|
267 |
-
# References
|
268 |
-
gr.Markdown(markdown_content)
|
269 |
|
270 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
271 |
submit_button.click(
|
272 |
-
fn=run_nnunet_predict,
|
273 |
-
inputs=[flair_input],
|
274 |
outputs=[seg_output, input_img, output_img]
|
275 |
)
|
276 |
|
@@ -279,8 +254,9 @@ if torch.cuda.is_available():
|
|
279 |
print(f"GPU is available: {torch.cuda.get_device_name(0)}")
|
280 |
else:
|
281 |
print("No GPU available. Falling back to CPU.")
|
282 |
-
os.system("nvidia-smi")
|
|
|
|
|
283 |
|
284 |
-
# Launch the app
|
285 |
if __name__ == "__main__":
|
286 |
demo.launch(share=True)
|
|
|
214 |
except subprocess.CalledProcessError as e:
|
215 |
return f"Error: {e}"
|
216 |
|
217 |
+
# Gradio interface with adjusted layout
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
218 |
with gr.Blocks() as demo:
|
|
|
219 |
gr.Markdown("""
|
220 |
# FLAMeS: Multiple Sclerosis Lesion Segmentation
|
221 |
|
222 |
Upload a skull-stripped FLAIR image (.nii.gz) to generate a binary segmentation of multiple sclerosis lesions.
|
223 |
""")
|
224 |
+
|
|
|
225 |
with gr.Row():
|
226 |
+
with gr.Column(scale=1):
|
227 |
flair_input = gr.File(label="Upload FLAIR Image (.nii.gz)")
|
228 |
submit_button = gr.Button("Submit")
|
229 |
+
with gr.Column(scale=2):
|
230 |
seg_output = gr.File(label="Download Segmentation Mask")
|
231 |
input_img = gr.Image(label="Input: FLAIR image")
|
232 |
output_img = gr.Image(label="Output: Lesion Mask")
|
|
|
|
|
|
|
233 |
|
234 |
+
gr.Markdown("""
|
235 |
+
**If you find this tool useful, please consider citing:**
|
236 |
+
|
237 |
+
1. A Deep Learning-Based Pipeline for Longitudinal White Matter Lesion Segmentation Using Diverse FLAIR Images
|
238 |
+
F. La Rosa, J. Dos Santos Silva, et al.
|
239 |
+
*Multiple Sclerosis Journal.* DOI: [10.1177/13524585231169437](https://doi.org/10.1177/13524585231169437)
|
240 |
+
|
241 |
+
2. nnU-Net: A Self-Configuring Method for Deep Learning-Based Biomedical Image Segmentation
|
242 |
+
F. Isensee, et al.
|
243 |
+
*Nature Methods.* DOI: [10.1038/s41592-020-01008-z](https://www.nature.com/articles/s41592-020-01008-z)
|
244 |
+
""")
|
245 |
+
|
246 |
submit_button.click(
|
247 |
+
fn=run_nnunet_predict,
|
248 |
+
inputs=[flair_input],
|
249 |
outputs=[seg_output, input_img, output_img]
|
250 |
)
|
251 |
|
|
|
254 |
print(f"GPU is available: {torch.cuda.get_device_name(0)}")
|
255 |
else:
|
256 |
print("No GPU available. Falling back to CPU.")
|
257 |
+
os.system("nvidia-smi")
|
258 |
+
|
259 |
+
download_model()
|
260 |
|
|
|
261 |
if __name__ == "__main__":
|
262 |
demo.launch(share=True)
|