Spaces:
Paused
Paused
Commit
路
0b07cd5
1
Parent(s):
33762af
added report download feature
Browse files
app.py
CHANGED
|
@@ -96,19 +96,69 @@ def process_img(img, brain_slice):
|
|
| 96 |
|
| 97 |
return brain, fig, update_slider, gr.update(visible=True)
|
| 98 |
|
| 99 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
# Extracci贸n de caracter铆sticas de imagen
|
| 101 |
features = utils.get_features(brain_img, mednet_model)
|
| 102 |
|
| 103 |
# Clasificaci贸n de imagen
|
| 104 |
label_img = np.array([svm_model.predict(features)])
|
| 105 |
|
| 106 |
-
if
|
| 107 |
sex_dum = 1
|
| 108 |
else:
|
| 109 |
sex_dum = 0
|
| 110 |
|
| 111 |
-
scores = np.array([
|
| 112 |
|
| 113 |
print(scores)
|
| 114 |
|
|
@@ -123,12 +173,19 @@ def get_diagnosis(brain_img, age, MMSE, GDSCALE, CDR, FAQ, NPI, sex):
|
|
| 123 |
|
| 124 |
# Probabilidad de tener MCI
|
| 125 |
print(prob)
|
| 126 |
-
diagnosis = f"The patient has a probability of {(100*prob):.2f}%
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
|
| 128 |
-
return gr.update(value=diagnosis)
|
|
|
|
| 129 |
|
| 130 |
def clear():
|
| 131 |
-
return gr.File.update(value=None), gr.Plot.update(value=None), gr.update(visible=False), gr.Plot.update(value=None), gr.update(visible=False), gr.update(value="The diagnosis will show here..."), gr.update(visible=False), gr.update(visible=False)
|
| 132 |
|
| 133 |
|
| 134 |
'''--------------------------------- Interfaz ---------------------------------'''
|
|
@@ -200,8 +257,10 @@ with gr.Blocks(theme=gr.themes.Base()) as demo:
|
|
| 200 |
with gr.Tab("Medications"):
|
| 201 |
input_medications = gr.Textbox(label='Medications', lines=5)
|
| 202 |
input_allergies = gr.Textbox(label='Allergies', lines=5)
|
| 203 |
-
|
| 204 |
-
|
|
|
|
|
|
|
| 205 |
|
| 206 |
with gr.Row():
|
| 207 |
# Bot贸n para cargar imagen
|
|
@@ -215,6 +274,11 @@ with gr.Blocks(theme=gr.themes.Base()) as demo:
|
|
| 215 |
|
| 216 |
# Bot贸n para obtener diagnostico
|
| 217 |
diagnostic_button = gr.Button(value="Get diagnosis", visible=False, variant="primary")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 218 |
|
| 219 |
# Outputs
|
| 220 |
with gr.Column(variant="panel", scale=1):
|
|
@@ -292,12 +356,16 @@ with gr.Blocks(theme=gr.themes.Base()) as demo:
|
|
| 292 |
|
| 293 |
# Actualizar diagnostico
|
| 294 |
diagnostic_button.click(fn=get_diagnosis,
|
| 295 |
-
inputs=[brain_img,
|
| 296 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 297 |
|
| 298 |
# Limpiar campos
|
| 299 |
clear_button.click(fn=clear,
|
| 300 |
-
outputs=[input_file, plot_img_original, mri_slider, plot_brain, brain_slider, diagnosis_text, process_button, diagnostic_button])
|
| 301 |
|
| 302 |
|
| 303 |
|
|
|
|
| 96 |
|
| 97 |
return brain, fig, update_slider, gr.update(visible=True)
|
| 98 |
|
| 99 |
+
def save_file(input_name, input_age, input_phone_num, input_emer_name, input_emer_phone_num,
|
| 100 |
+
input_sex, input_MMSE, input_GDSCALE, input_CDR, input_FAQ, input_NPI_Q, input_Diastolic_blood_pressure,
|
| 101 |
+
input_Systolic_blood_pressure, input_Body_heigth, input_Body_weight, input_Heart_rate,
|
| 102 |
+
input_Respiratory_rate, input_Body_temperature, input_Pluse_oximetry,
|
| 103 |
+
input_medications, input_allergies,diagnosis):
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
with open('results.txt', 'w') as f:
|
| 107 |
+
# Save Patient Data
|
| 108 |
+
f.write("Patient data:\n")
|
| 109 |
+
f.write(f"\tName: {input_name.capitalize()}\n")
|
| 110 |
+
f.write(f"\tSex: {input_sex}\n")
|
| 111 |
+
f.write(f"\tAge: {input_age}\n")
|
| 112 |
+
f.write(f"\tPhone Number: {input_phone_num}\n")
|
| 113 |
+
f.write(f"\tEmergency Contact Name: {input_emer_name.capitalize()}\n")
|
| 114 |
+
f.write(f"\tEmergency Contact Phone Number: {input_emer_phone_num}\n\n")
|
| 115 |
+
|
| 116 |
+
# Save Vital Signs
|
| 117 |
+
f.write("Vital Signs:\n")
|
| 118 |
+
f.write(f"\tDiastolic blood pressure: {input_Diastolic_blood_pressure} mm Hg\n")
|
| 119 |
+
f.write(f"\tSystolic blood pressure: {input_Systolic_blood_pressure} mm Hg\n")
|
| 120 |
+
f.write(f"\tBody height: {input_Body_heigth} cm\n")
|
| 121 |
+
f.write(f"\tBody weight: {input_Body_weight} kg\n")
|
| 122 |
+
f.write(f"\tHeart rate: {input_Heart_rate} bpm\n")
|
| 123 |
+
f.write(f"\tRespiratory rate: {input_Respiratory_rate} bpm\n")
|
| 124 |
+
f.write(f"\tBody temperature: {input_Body_temperature} 掳C\n")
|
| 125 |
+
f.write(f"\tPulse oximetry: {input_Pluse_oximetry}%\n\n")
|
| 126 |
+
|
| 127 |
+
# Save Medications
|
| 128 |
+
f.write("Medications:\n")
|
| 129 |
+
f.write(f"\tMedications: {input_medications}\n")
|
| 130 |
+
f.write(f"\tAllergies: {input_allergies}\n\n")
|
| 131 |
+
|
| 132 |
+
# Save clinical data
|
| 133 |
+
f.write("Clinical data:\n")
|
| 134 |
+
f.write(f"\tMMSE total score: {input_MMSE}\n")
|
| 135 |
+
f.write(f"\tGDSCALE total score: {input_GDSCALE}\n")
|
| 136 |
+
f.write(f"\tGlobal CDR: {input_CDR}\n")
|
| 137 |
+
f.write(f"\tFAQ total score: {input_FAQ}\n")
|
| 138 |
+
f.write(f"\tNPI-Q total score: {input_NPI_Q}\n")
|
| 139 |
+
|
| 140 |
+
# Save Diagnosis
|
| 141 |
+
f.write("Diagnosis:\n")
|
| 142 |
+
f.write(f"\t{diagnosis}\n")
|
| 143 |
+
|
| 144 |
+
def get_diagnosis(brain_img, input_name, input_age, input_phone_num, input_emer_name, input_emer_phone_num,
|
| 145 |
+
input_sex, input_MMSE, input_GDSCALE, input_CDR, input_FAQ, input_NPI_Q, input_Diastolic_blood_pressure,
|
| 146 |
+
input_Systolic_blood_pressure, input_Body_heigth, input_Body_weight, input_Heart_rate,
|
| 147 |
+
input_Respiratory_rate, input_Body_temperature, input_Pluse_oximetry,
|
| 148 |
+
input_medications, input_allergies):
|
| 149 |
+
|
| 150 |
# Extracci贸n de caracter铆sticas de imagen
|
| 151 |
features = utils.get_features(brain_img, mednet_model)
|
| 152 |
|
| 153 |
# Clasificaci贸n de imagen
|
| 154 |
label_img = np.array([svm_model.predict(features)])
|
| 155 |
|
| 156 |
+
if input_sex == "Male":
|
| 157 |
sex_dum = 1
|
| 158 |
else:
|
| 159 |
sex_dum = 0
|
| 160 |
|
| 161 |
+
scores = np.array([input_age, input_MMSE, input_GDSCALE, input_CDR, input_FAQ, input_NPI_Q, sex_dum, label_img])
|
| 162 |
|
| 163 |
print(scores)
|
| 164 |
|
|
|
|
| 173 |
|
| 174 |
# Probabilidad de tener MCI
|
| 175 |
print(prob)
|
| 176 |
+
diagnosis = f"The patient has a probability of {(100*prob):.2f}% of having MCI"
|
| 177 |
+
|
| 178 |
+
save_file(input_name, input_age, input_phone_num, input_emer_name, input_emer_phone_num,
|
| 179 |
+
input_sex, input_MMSE, input_GDSCALE, input_CDR, input_FAQ, input_NPI_Q, input_Diastolic_blood_pressure,
|
| 180 |
+
input_Systolic_blood_pressure, input_Body_heigth, input_Body_weight, input_Heart_rate,
|
| 181 |
+
input_Respiratory_rate, input_Body_temperature, input_Pluse_oximetry,
|
| 182 |
+
input_medications, input_allergies,diagnosis)
|
| 183 |
|
| 184 |
+
return gr.update(value=diagnosis), gr.update(value="results.txt", visible=True), gr.update(visible=True)
|
| 185 |
+
|
| 186 |
|
| 187 |
def clear():
|
| 188 |
+
return gr.File.update(value=None), gr.Plot.update(value=None), gr.update(visible=False), gr.Plot.update(value=None), gr.update(visible=False), gr.update(value="The diagnosis will show here..."), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
| 189 |
|
| 190 |
|
| 191 |
'''--------------------------------- Interfaz ---------------------------------'''
|
|
|
|
| 257 |
with gr.Tab("Medications"):
|
| 258 |
input_medications = gr.Textbox(label='Medications', lines=5)
|
| 259 |
input_allergies = gr.Textbox(label='Allergies', lines=5)
|
| 260 |
+
|
| 261 |
+
with gr.Box():
|
| 262 |
+
gr.Markdown('<h4 style="color:#235784;">Upload MRI</h4>')
|
| 263 |
+
input_file = gr.File(file_count="single", label="MRI File (.nii)", file_types=[".nii"], show_label=False)
|
| 264 |
|
| 265 |
with gr.Row():
|
| 266 |
# Bot贸n para cargar imagen
|
|
|
|
| 274 |
|
| 275 |
# Bot贸n para obtener diagnostico
|
| 276 |
diagnostic_button = gr.Button(value="Get diagnosis", visible=False, variant="primary")
|
| 277 |
+
|
| 278 |
+
with gr.Box(visible=False) as download_box:
|
| 279 |
+
gr.Markdown('<h4 style="color:#235784;"> Dowload diagnosis report</h4>')
|
| 280 |
+
# Descarga de archivo
|
| 281 |
+
output_file = gr.File(file_count="single", show_label=False, interactive=False, visible=True)
|
| 282 |
|
| 283 |
# Outputs
|
| 284 |
with gr.Column(variant="panel", scale=1):
|
|
|
|
| 356 |
|
| 357 |
# Actualizar diagnostico
|
| 358 |
diagnostic_button.click(fn=get_diagnosis,
|
| 359 |
+
inputs=[brain_img, input_name, input_age, input_phone_num, input_emer_name, input_emer_phone_num,
|
| 360 |
+
input_sex, input_MMSE, input_GDSCALE, input_CDR, input_FAQ, input_NPI_Q, input_Diastolic_blood_pressure,
|
| 361 |
+
input_Systolic_blood_pressure, input_Body_heigth, input_Body_weight, input_Heart_rate,
|
| 362 |
+
input_Respiratory_rate, input_Body_temperature, input_Pluse_oximetry,
|
| 363 |
+
input_medications, input_allergies],
|
| 364 |
+
outputs=[diagnosis_text, output_file, download_box])
|
| 365 |
|
| 366 |
# Limpiar campos
|
| 367 |
clear_button.click(fn=clear,
|
| 368 |
+
outputs=[input_file, plot_img_original, mri_slider, plot_brain, brain_slider, diagnosis_text, process_button, diagnostic_button, download_box])
|
| 369 |
|
| 370 |
|
| 371 |
|