Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -75,7 +75,7 @@ def prepare_transforms():
|
|
75 |
torchio.transforms.ZNormalization(masking_method=lambda x: x > 0, keys=["image"])
|
76 |
])
|
77 |
|
78 |
-
#
|
79 |
def preprocess_mri(nifti_path):
|
80 |
transforms = prepare_transforms()
|
81 |
data_dict = {"image": nifti_path}
|
@@ -83,14 +83,11 @@ def preprocess_mri(nifti_path):
|
|
83 |
dataloader = DataLoader(dataset, batch_size=1, num_workers=0)
|
84 |
return next(iter(dataloader))["image"].to(device)
|
85 |
|
86 |
-
#
|
87 |
@spaces.GPU(duration=90)
|
88 |
-
def
|
89 |
return f"Brain Age estimate: 42", age
|
90 |
|
91 |
-
def predict_brain_age(nifti_file, age, sex):
|
92 |
-
return predict_brain_age_core(nifti_file.name, age, sex)
|
93 |
-
|
94 |
"""
|
95 |
def predict_brain_age(nifti_file, actual_age): #sex
|
96 |
if not os.path.exists(nifti_file.name):
|
@@ -156,11 +153,7 @@ with gr.Blocks() as demo:
|
|
156 |
brain_age_output = gr.Textbox(label="Predicted Brain Age", interactive=False)
|
157 |
bad_output = gr.Textbox(label="Brain Age Difference", interactive=False)
|
158 |
|
159 |
-
submit_button.click(
|
160 |
-
fn=predict_brain_age,
|
161 |
-
inputs=[mri_input, age_input, sex_input],
|
162 |
-
outputs=[brain_age_output, bad_output]
|
163 |
-
)
|
164 |
|
165 |
gr.Markdown("""
|
166 |
**Disclaimer:** This is a research tool and is not intended for clinical use.
|
|
|
75 |
torchio.transforms.ZNormalization(masking_method=lambda x: x > 0, keys=["image"])
|
76 |
])
|
77 |
|
78 |
+
# Process MRI File
|
79 |
def preprocess_mri(nifti_path):
|
80 |
transforms = prepare_transforms()
|
81 |
data_dict = {"image": nifti_path}
|
|
|
83 |
dataloader = DataLoader(dataset, batch_size=1, num_workers=0)
|
84 |
return next(iter(dataloader))["image"].to(device)
|
85 |
|
86 |
+
# Run Brain Age Prediction (Decorated for GPU Execution)
|
87 |
@spaces.GPU(duration=90)
|
88 |
+
def predict_brain_age(path, age, sex): #, actual_age):
|
89 |
return f"Brain Age estimate: 42", age
|
90 |
|
|
|
|
|
|
|
91 |
"""
|
92 |
def predict_brain_age(nifti_file, actual_age): #sex
|
93 |
if not os.path.exists(nifti_file.name):
|
|
|
153 |
brain_age_output = gr.Textbox(label="Predicted Brain Age", interactive=False)
|
154 |
bad_output = gr.Textbox(label="Brain Age Difference", interactive=False)
|
155 |
|
156 |
+
submit_button.click(fn=predict_brain_age, inputs=[mri_input, age_input, sex_input], outputs=[brain_age_output, bad_output])
|
|
|
|
|
|
|
|
|
157 |
|
158 |
gr.Markdown("""
|
159 |
**Disclaimer:** This is a research tool and is not intended for clinical use.
|