Spaces:
Sleeping
Sleeping
chore: update
Browse files
app.py
CHANGED
@@ -115,12 +115,12 @@ def get_features_fn(*checked_symptoms: Tuple[str]) -> Dict:
|
|
115 |
print("Provide at least 5 symptoms.")
|
116 |
return {
|
117 |
error_box1: gr.update(visible=True, value="⚠️ Provide at least 5 symptoms"),
|
118 |
-
|
119 |
}
|
120 |
|
121 |
return {
|
122 |
error_box1: gr.update(visible=False),
|
123 |
-
|
124 |
visible=False,
|
125 |
value=get_user_symptoms_from_checkboxgroup(pretty_print(checked_symptoms)),
|
126 |
),
|
@@ -217,7 +217,7 @@ def encrypt_fn(user_symptoms: np.ndarray, user_id: str) -> None:
|
|
217 |
|
218 |
return {
|
219 |
error_box3: gr.update(visible=False),
|
220 |
-
|
221 |
enc_vect_box: gr.update(visible=True, value=encrypted_quantized_user_symptoms_shorten_hex),
|
222 |
}
|
223 |
|
@@ -435,19 +435,19 @@ def decrypt_fn(
|
|
435 |
top3_diseases = np.argsort(output.flatten())[-3:][::-1]
|
436 |
top3_proba = output[0][top3_diseases]
|
437 |
|
|
|
|
|
438 |
if (
|
439 |
(top3_proba[0] < threshold)
|
440 |
or (np.sum(top3_proba) < threshold)
|
441 |
or (abs(top3_proba[0] - top3_proba[1]) < threshold)
|
442 |
):
|
443 |
-
out = "⚠️ The prediction appears uncertain; including more symptoms may improve the results
|
444 |
-
|
445 |
-
else:
|
446 |
-
out = ""
|
447 |
|
448 |
out = (
|
449 |
-
f"{out}"
|
450 |
-
|
|
|
451 |
"Here are the top3 predictions:\n\n"
|
452 |
f"1. « {get_disease_name(top3_diseases[0])} » with a probability of {top3_proba[0]:.2%}\n"
|
453 |
f"2. « {get_disease_name(top3_diseases[1])} » with a probability of {top3_proba[1]:.2%}\n"
|
@@ -467,18 +467,18 @@ def reset_fn():
|
|
467 |
clean_directory()
|
468 |
|
469 |
return {
|
470 |
-
|
471 |
-
|
|
|
|
|
472 |
user_id_box: gr.update(visible=False, value=None),
|
473 |
-
one_hot_vector: None,
|
474 |
default_symptoms: gr.update(visible=True, value=None),
|
475 |
-
|
476 |
-
quant_vect_box: gr.update(visible=False, value=None),
|
477 |
-
enc_vect_box: gr.update(visible=True, value=None),
|
478 |
key_box: gr.update(visible=True, value=None),
|
479 |
key_len_box: gr.update(visible=False, value=None),
|
480 |
fhe_execution_time_box: gr.update(visible=True, value=None),
|
481 |
decrypt_box: None,
|
|
|
482 |
error_box7: gr.update(visible=False),
|
483 |
error_box1: gr.update(visible=False),
|
484 |
error_box2: gr.update(visible=False),
|
@@ -570,24 +570,24 @@ if __name__ == "__main__":
|
|
570 |
|
571 |
with gr.Row():
|
572 |
with gr.Column(scale=2):
|
573 |
-
|
574 |
with gr.Column(scale=5):
|
575 |
default_symptoms = gr.Textbox(label="Related Symptoms:", visible=False)
|
576 |
# User vector symptoms encoded in oneHot representation
|
577 |
-
|
578 |
# Submit botton
|
579 |
submit_btn = gr.Button("Submit")
|
580 |
# Clear botton
|
581 |
clear_button = gr.Button("Reset Space 🔁", visible=False)
|
582 |
|
583 |
-
|
584 |
-
fn=display_default_symptoms_fn, inputs=[
|
585 |
)
|
586 |
|
587 |
submit_btn.click(
|
588 |
fn=get_features_fn,
|
589 |
inputs=[*check_boxes],
|
590 |
-
outputs=[
|
591 |
)
|
592 |
|
593 |
# ------------------------- Step 2 -------------------------
|
@@ -611,7 +611,7 @@ if __name__ == "__main__":
|
|
611 |
|
612 |
gen_key_btn.click(
|
613 |
key_gen_fn,
|
614 |
-
inputs=
|
615 |
outputs=[
|
616 |
key_box,
|
617 |
user_id_box,
|
@@ -628,15 +628,15 @@ if __name__ == "__main__":
|
|
628 |
|
629 |
with gr.Row():
|
630 |
with gr.Column():
|
631 |
-
|
632 |
with gr.Column():
|
633 |
enc_vect_box = gr.Textbox(label="Encrypted Vector:", max_lines=10)
|
634 |
|
635 |
encrypt_btn.click(
|
636 |
encrypt_fn,
|
637 |
-
inputs=[
|
638 |
outputs=[
|
639 |
-
|
640 |
enc_vect_box,
|
641 |
error_box3,
|
642 |
],
|
@@ -655,7 +655,7 @@ if __name__ == "__main__":
|
|
655 |
|
656 |
send_input_btn.click(
|
657 |
send_input_fn,
|
658 |
-
inputs=[user_id_box,
|
659 |
outputs=[error_box4, srv_resp_send_data_box],
|
660 |
)
|
661 |
|
@@ -698,7 +698,7 @@ if __name__ == "__main__":
|
|
698 |
|
699 |
get_output_btn.click(
|
700 |
get_output_fn,
|
701 |
-
inputs=[user_id_box,
|
702 |
outputs=[srv_resp_retrieve_data_box, error_box6],
|
703 |
)
|
704 |
|
@@ -710,7 +710,7 @@ if __name__ == "__main__":
|
|
710 |
|
711 |
decrypt_btn.click(
|
712 |
decrypt_fn,
|
713 |
-
inputs=[user_id_box,
|
714 |
outputs=[decrypt_box, error_box7, submit_btn],
|
715 |
)
|
716 |
|
@@ -734,10 +734,9 @@ if __name__ == "__main__":
|
|
734 |
clear_button.click(
|
735 |
reset_fn,
|
736 |
outputs=[
|
737 |
-
|
738 |
-
|
739 |
submit_btn,
|
740 |
-
# disease_box,
|
741 |
error_box1,
|
742 |
error_box2,
|
743 |
error_box3,
|
@@ -745,7 +744,7 @@ if __name__ == "__main__":
|
|
745 |
error_box5,
|
746 |
error_box6,
|
747 |
error_box7,
|
748 |
-
|
749 |
default_symptoms,
|
750 |
user_id_box,
|
751 |
key_len_box,
|
|
|
115 |
print("Provide at least 5 symptoms.")
|
116 |
return {
|
117 |
error_box1: gr.update(visible=True, value="⚠️ Provide at least 5 symptoms"),
|
118 |
+
one_hot_vect: None,
|
119 |
}
|
120 |
|
121 |
return {
|
122 |
error_box1: gr.update(visible=False),
|
123 |
+
one_hot_vect: gr.update(
|
124 |
visible=False,
|
125 |
value=get_user_symptoms_from_checkboxgroup(pretty_print(checked_symptoms)),
|
126 |
),
|
|
|
217 |
|
218 |
return {
|
219 |
error_box3: gr.update(visible=False),
|
220 |
+
one_hot_vect_box: gr.update(visible=True, value=user_symptoms),
|
221 |
enc_vect_box: gr.update(visible=True, value=encrypted_quantized_user_symptoms_shorten_hex),
|
222 |
}
|
223 |
|
|
|
435 |
top3_diseases = np.argsort(output.flatten())[-3:][::-1]
|
436 |
top3_proba = output[0][top3_diseases]
|
437 |
|
438 |
+
out = ""
|
439 |
+
|
440 |
if (
|
441 |
(top3_proba[0] < threshold)
|
442 |
or (np.sum(top3_proba) < threshold)
|
443 |
or (abs(top3_proba[0] - top3_proba[1]) < threshold)
|
444 |
):
|
445 |
+
out = "⚠️ The prediction appears uncertain; including more symptoms may improve the results."
|
|
|
|
|
|
|
446 |
|
447 |
out = (
|
448 |
+
f"{out}\n"
|
449 |
+
"Given the symptoms you provided: "
|
450 |
+
f"{pretty_print(checked_symptoms, case_conversion=str.capitalize, delimiter=', ')}\n\n"
|
451 |
"Here are the top3 predictions:\n\n"
|
452 |
f"1. « {get_disease_name(top3_diseases[0])} » with a probability of {top3_proba[0]:.2%}\n"
|
453 |
f"2. « {get_disease_name(top3_diseases[1])} » with a probability of {top3_proba[1]:.2%}\n"
|
|
|
467 |
clean_directory()
|
468 |
|
469 |
return {
|
470 |
+
one_hot_vect: None,
|
471 |
+
one_hot_vect_box: None,
|
472 |
+
enc_vect_box: gr.update(visible=True, value=None),
|
473 |
+
quant_vect_box: gr.update(visible=False, value=None),
|
474 |
user_id_box: gr.update(visible=False, value=None),
|
|
|
475 |
default_symptoms: gr.update(visible=True, value=None),
|
476 |
+
default_disease_box: gr.update(visible=True, value=None),
|
|
|
|
|
477 |
key_box: gr.update(visible=True, value=None),
|
478 |
key_len_box: gr.update(visible=False, value=None),
|
479 |
fhe_execution_time_box: gr.update(visible=True, value=None),
|
480 |
decrypt_box: None,
|
481 |
+
submit_btn: gr.update(value="Submit"),
|
482 |
error_box7: gr.update(visible=False),
|
483 |
error_box1: gr.update(visible=False),
|
484 |
error_box2: gr.update(visible=False),
|
|
|
570 |
|
571 |
with gr.Row():
|
572 |
with gr.Column(scale=2):
|
573 |
+
default_disease_box = gr.Dropdown(sorted(diseases), label="Diseases", visible=False)
|
574 |
with gr.Column(scale=5):
|
575 |
default_symptoms = gr.Textbox(label="Related Symptoms:", visible=False)
|
576 |
# User vector symptoms encoded in oneHot representation
|
577 |
+
one_hot_vect = gr.Textbox(visible=False)
|
578 |
# Submit botton
|
579 |
submit_btn = gr.Button("Submit")
|
580 |
# Clear botton
|
581 |
clear_button = gr.Button("Reset Space 🔁", visible=False)
|
582 |
|
583 |
+
default_disease_box.change(
|
584 |
+
fn=display_default_symptoms_fn, inputs=[default_disease_box], outputs=[default_symptoms]
|
585 |
)
|
586 |
|
587 |
submit_btn.click(
|
588 |
fn=get_features_fn,
|
589 |
inputs=[*check_boxes],
|
590 |
+
outputs=[one_hot_vect, error_box1, submit_btn],
|
591 |
)
|
592 |
|
593 |
# ------------------------- Step 2 -------------------------
|
|
|
611 |
|
612 |
gen_key_btn.click(
|
613 |
key_gen_fn,
|
614 |
+
inputs=one_hot_vect,
|
615 |
outputs=[
|
616 |
key_box,
|
617 |
user_id_box,
|
|
|
628 |
|
629 |
with gr.Row():
|
630 |
with gr.Column():
|
631 |
+
one_hot_vect_box = gr.Textbox(label="User Symptoms Vector:", max_lines=10)
|
632 |
with gr.Column():
|
633 |
enc_vect_box = gr.Textbox(label="Encrypted Vector:", max_lines=10)
|
634 |
|
635 |
encrypt_btn.click(
|
636 |
encrypt_fn,
|
637 |
+
inputs=[one_hot_vect, user_id_box],
|
638 |
outputs=[
|
639 |
+
one_hot_vect_box,
|
640 |
enc_vect_box,
|
641 |
error_box3,
|
642 |
],
|
|
|
655 |
|
656 |
send_input_btn.click(
|
657 |
send_input_fn,
|
658 |
+
inputs=[user_id_box, one_hot_vect],
|
659 |
outputs=[error_box4, srv_resp_send_data_box],
|
660 |
)
|
661 |
|
|
|
698 |
|
699 |
get_output_btn.click(
|
700 |
get_output_fn,
|
701 |
+
inputs=[user_id_box, one_hot_vect],
|
702 |
outputs=[srv_resp_retrieve_data_box, error_box6],
|
703 |
)
|
704 |
|
|
|
710 |
|
711 |
decrypt_btn.click(
|
712 |
decrypt_fn,
|
713 |
+
inputs=[user_id_box, one_hot_vect, *check_boxes],
|
714 |
outputs=[decrypt_box, error_box7, submit_btn],
|
715 |
)
|
716 |
|
|
|
734 |
clear_button.click(
|
735 |
reset_fn,
|
736 |
outputs=[
|
737 |
+
one_hot_vect_box,
|
738 |
+
one_hot_vect,
|
739 |
submit_btn,
|
|
|
740 |
error_box1,
|
741 |
error_box2,
|
742 |
error_box3,
|
|
|
744 |
error_box5,
|
745 |
error_box6,
|
746 |
error_box7,
|
747 |
+
default_disease_box,
|
748 |
default_symptoms,
|
749 |
user_id_box,
|
750 |
key_len_box,
|