Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
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 |
|
@@ -418,7 +418,7 @@ def decrypt_fn(
|
|
418 |
"- the server processed the encrypted data \n"
|
419 |
"- the Client received the data from the Server before decrypting the prediction",
|
420 |
),
|
421 |
-
|
422 |
}
|
423 |
|
424 |
# Load the encrypted output as bytes
|
@@ -456,7 +456,7 @@ def decrypt_fn(
|
|
456 |
|
457 |
return {
|
458 |
error_box7: gr.update(visible=False),
|
459 |
-
|
460 |
submit_btn: gr.update(value="Submit")
|
461 |
}
|
462 |
|
@@ -467,10 +467,10 @@ def reset_fn():
|
|
467 |
clean_directory()
|
468 |
|
469 |
return {
|
470 |
-
|
471 |
submit_btn: gr.update(value="Submit"),
|
472 |
user_id_box: gr.update(visible=False, value=None, interactive=False),
|
473 |
-
|
474 |
default_symptoms: gr.update(visible=True, value=None),
|
475 |
disease_box: gr.update(visible=True, value=None),
|
476 |
quant_vect_box: gr.update(visible=False, value=None, interactive=False),
|
@@ -478,7 +478,7 @@ def reset_fn():
|
|
478 |
key_box: gr.update(visible=True, value=None, interactive=False),
|
479 |
key_len_box: gr.update(visible=False, value=None, interactive=False),
|
480 |
fhe_execution_time_box: gr.update(visible=True, value=None, interactive=False),
|
481 |
-
|
482 |
error_box7: gr.update(visible=False),
|
483 |
error_box1: gr.update(visible=False),
|
484 |
error_box2: gr.update(visible=False),
|
@@ -572,7 +572,7 @@ if __name__ == "__main__":
|
|
572 |
label="Related Symptoms:", interactive=False, visible=False,
|
573 |
)
|
574 |
# User vector symptoms encoded in oneHot representation
|
575 |
-
|
576 |
# Submit botton
|
577 |
submit_btn = gr.Button("Submit")
|
578 |
# Clear botton
|
@@ -584,7 +584,7 @@ if __name__ == "__main__":
|
|
584 |
submit_btn.click(
|
585 |
fn=get_features_fn,
|
586 |
inputs=[*check_boxes],
|
587 |
-
outputs=[
|
588 |
)
|
589 |
|
590 |
# ------------------------- Step 2 -------------------------
|
@@ -607,7 +607,7 @@ if __name__ == "__main__":
|
|
607 |
|
608 |
gen_key_btn.click(
|
609 |
key_gen_fn,
|
610 |
-
inputs=
|
611 |
outputs=[
|
612 |
key_box,
|
613 |
user_id_box,
|
@@ -624,15 +624,15 @@ if __name__ == "__main__":
|
|
624 |
|
625 |
with gr.Row():
|
626 |
with gr.Column():
|
627 |
-
|
628 |
with gr.Column():
|
629 |
enc_vect_box = gr.Textbox(label="Encrypted Vector:", max_lines=10)
|
630 |
|
631 |
encrypt_btn.click(
|
632 |
encrypt_fn,
|
633 |
-
inputs=[
|
634 |
outputs=[
|
635 |
-
|
636 |
enc_vect_box,
|
637 |
error_box3,
|
638 |
],
|
@@ -651,7 +651,7 @@ if __name__ == "__main__":
|
|
651 |
|
652 |
send_input_btn.click(
|
653 |
send_input_fn,
|
654 |
-
inputs=[user_id_box,
|
655 |
outputs=[error_box4, srv_resp_send_data_box],
|
656 |
)
|
657 |
|
@@ -666,10 +666,7 @@ if __name__ == "__main__":
|
|
666 |
|
667 |
run_fhe_btn = gr.Button("Run the FHE evaluation")
|
668 |
error_box5 = gr.Textbox(label="Error ❌", visible=False)
|
669 |
-
fhe_execution_time_box = gr.Textbox(
|
670 |
-
label="Total FHE Execution Time:", interactive=False, visible=True
|
671 |
-
)
|
672 |
-
|
673 |
run_fhe_btn.click(
|
674 |
run_fhe_fn,
|
675 |
inputs=[user_id_box],
|
@@ -684,6 +681,7 @@ if __name__ == "__main__":
|
|
684 |
|
685 |
error_box6 = gr.Textbox(label="Error ❌", visible=False)
|
686 |
|
|
|
687 |
with gr.Row().style(equal_height=True):
|
688 |
with gr.Column(scale=4):
|
689 |
get_output_btn = gr.Button("Get data")
|
@@ -694,21 +692,20 @@ if __name__ == "__main__":
|
|
694 |
|
695 |
get_output_btn.click(
|
696 |
get_output_fn,
|
697 |
-
inputs=[user_id_box,
|
698 |
outputs=[srv_resp_retrieve_data_box, error_box6],
|
699 |
)
|
700 |
|
|
|
701 |
gr.Markdown("### Decrypt the output")
|
702 |
-
|
703 |
-
decrypt_target_btn = gr.Button("Decrypt the output using the private secret key")
|
704 |
-
|
705 |
error_box7 = gr.Textbox(label="Error ❌", visible=False)
|
706 |
-
|
707 |
|
708 |
-
|
709 |
decrypt_fn,
|
710 |
-
inputs=[user_id_box,
|
711 |
-
outputs=[
|
712 |
)
|
713 |
|
714 |
# ------------------------- End -------------------------
|
@@ -729,8 +726,8 @@ if __name__ == "__main__":
|
|
729 |
clear_button.click(
|
730 |
reset_fn,
|
731 |
outputs=[
|
732 |
-
|
733 |
-
|
734 |
submit_btn,
|
735 |
# disease_box,
|
736 |
error_box1,
|
@@ -750,7 +747,7 @@ if __name__ == "__main__":
|
|
750 |
srv_resp_send_data_box,
|
751 |
srv_resp_retrieve_data_box,
|
752 |
fhe_execution_time_box,
|
753 |
-
|
754 |
*check_boxes,
|
755 |
],
|
756 |
)
|
|
|
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_vector: None,
|
119 |
}
|
120 |
|
121 |
return {
|
122 |
error_box1: gr.update(visible=False),
|
123 |
+
one_hot_vector: 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_vector_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 |
|
|
|
418 |
"- the server processed the encrypted data \n"
|
419 |
"- the Client received the data from the Server before decrypting the prediction",
|
420 |
),
|
421 |
+
decrypt_box: None,
|
422 |
}
|
423 |
|
424 |
# Load the encrypted output as bytes
|
|
|
456 |
|
457 |
return {
|
458 |
error_box7: gr.update(visible=False),
|
459 |
+
decrypt_box: out,
|
460 |
submit_btn: gr.update(value="Submit")
|
461 |
}
|
462 |
|
|
|
467 |
clean_directory()
|
468 |
|
469 |
return {
|
470 |
+
one_hot_vector_box: None,
|
471 |
submit_btn: gr.update(value="Submit"),
|
472 |
user_id_box: gr.update(visible=False, value=None, interactive=False),
|
473 |
+
one_hot_vector: None,
|
474 |
default_symptoms: gr.update(visible=True, value=None),
|
475 |
disease_box: gr.update(visible=True, value=None),
|
476 |
quant_vect_box: gr.update(visible=False, value=None, interactive=False),
|
|
|
478 |
key_box: gr.update(visible=True, value=None, interactive=False),
|
479 |
key_len_box: gr.update(visible=False, value=None, interactive=False),
|
480 |
fhe_execution_time_box: gr.update(visible=True, value=None, interactive=False),
|
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),
|
|
|
572 |
label="Related Symptoms:", interactive=False, visible=False,
|
573 |
)
|
574 |
# User vector symptoms encoded in oneHot representation
|
575 |
+
one_hot_vector = gr.Textbox(visible=False)
|
576 |
# Submit botton
|
577 |
submit_btn = gr.Button("Submit")
|
578 |
# Clear botton
|
|
|
584 |
submit_btn.click(
|
585 |
fn=get_features_fn,
|
586 |
inputs=[*check_boxes],
|
587 |
+
outputs=[one_hot_vector, error_box1, submit_btn],
|
588 |
)
|
589 |
|
590 |
# ------------------------- Step 2 -------------------------
|
|
|
607 |
|
608 |
gen_key_btn.click(
|
609 |
key_gen_fn,
|
610 |
+
inputs=one_hot_vector,
|
611 |
outputs=[
|
612 |
key_box,
|
613 |
user_id_box,
|
|
|
624 |
|
625 |
with gr.Row():
|
626 |
with gr.Column():
|
627 |
+
one_hot_vector_box = gr.Textbox(label="User Symptoms Vector:", max_lines=10)
|
628 |
with gr.Column():
|
629 |
enc_vect_box = gr.Textbox(label="Encrypted Vector:", max_lines=10)
|
630 |
|
631 |
encrypt_btn.click(
|
632 |
encrypt_fn,
|
633 |
+
inputs=[one_hot_vector, user_id_box],
|
634 |
outputs=[
|
635 |
+
one_hot_vector_box,
|
636 |
enc_vect_box,
|
637 |
error_box3,
|
638 |
],
|
|
|
651 |
|
652 |
send_input_btn.click(
|
653 |
send_input_fn,
|
654 |
+
inputs=[user_id_box, one_hot_vector],
|
655 |
outputs=[error_box4, srv_resp_send_data_box],
|
656 |
)
|
657 |
|
|
|
666 |
|
667 |
run_fhe_btn = gr.Button("Run the FHE evaluation")
|
668 |
error_box5 = gr.Textbox(label="Error ❌", visible=False)
|
669 |
+
fhe_execution_time_box = gr.Textbox(label="Total FHE Execution Time:", visible=True)
|
|
|
|
|
|
|
670 |
run_fhe_btn.click(
|
671 |
run_fhe_fn,
|
672 |
inputs=[user_id_box],
|
|
|
681 |
|
682 |
error_box6 = gr.Textbox(label="Error ❌", visible=False)
|
683 |
|
684 |
+
# Step 4.1: Data transmission
|
685 |
with gr.Row().style(equal_height=True):
|
686 |
with gr.Column(scale=4):
|
687 |
get_output_btn = gr.Button("Get data")
|
|
|
692 |
|
693 |
get_output_btn.click(
|
694 |
get_output_fn,
|
695 |
+
inputs=[user_id_box, one_hot_vector],
|
696 |
outputs=[srv_resp_retrieve_data_box, error_box6],
|
697 |
)
|
698 |
|
699 |
+
# Step 4.1: Data transmission
|
700 |
gr.Markdown("### Decrypt the output")
|
701 |
+
decrypt_btn = gr.Button("Decrypt the output using the private secret key")
|
|
|
|
|
702 |
error_box7 = gr.Textbox(label="Error ❌", visible=False)
|
703 |
+
decrypt_box = gr.Textbox(label="Decrypted Output:", interactive=False)
|
704 |
|
705 |
+
decrypt_btn.click(
|
706 |
decrypt_fn,
|
707 |
+
inputs=[user_id_box, one_hot_vector, *check_boxes],
|
708 |
+
outputs=[decrypt_box, error_box7, submit_btn],
|
709 |
)
|
710 |
|
711 |
# ------------------------- End -------------------------
|
|
|
726 |
clear_button.click(
|
727 |
reset_fn,
|
728 |
outputs=[
|
729 |
+
one_hot_vector_box,
|
730 |
+
one_hot_vector,
|
731 |
submit_btn,
|
732 |
# disease_box,
|
733 |
error_box1,
|
|
|
747 |
srv_resp_send_data_box,
|
748 |
srv_resp_retrieve_data_box,
|
749 |
fhe_execution_time_box,
|
750 |
+
decrypt_box,
|
751 |
*check_boxes,
|
752 |
],
|
753 |
)
|