chore: update design in version 6
Browse files
app.py
CHANGED
@@ -550,196 +550,206 @@ if __name__ == "__main__":
|
|
550 |
"Disclaimer: this demo is not to be used as a substitute for medical advice, diagnosis or treatment of any health condition. Any questions regarding your own health should be addressed to your physician or other healthcare provider."
|
551 |
)
|
552 |
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
label="Related Symptoms:", visible=True, interactive=False
|
591 |
-
)
|
592 |
-
|
593 |
-
disease_box.change(fn=display_default_symptoms_fn, inputs=[disease_box], outputs=[default_symptoms])
|
594 |
-
|
595 |
-
user_vect_box1 = gr.Textbox(visible=False)
|
596 |
-
|
597 |
-
with gr.Row():
|
598 |
-
with gr.Column():
|
599 |
-
# Submit botton
|
600 |
-
submit_button = gr.Button("Submit Symptoms π")
|
601 |
-
with gr.Column():
|
602 |
-
# Clear botton
|
603 |
-
clear_button = gr.Button("Reset Space π")
|
604 |
-
|
605 |
-
with gr.TabItem("2. Data Encryption", id=1):
|
606 |
-
gr.Markdown("## Step 2: Encrypt data")
|
607 |
-
gr.Markdown("<span style='color:grey'>Client Side</span>")
|
608 |
-
gr.Markdown("### Key Generation")
|
609 |
-
gr.Markdown(
|
610 |
-
"In FHE schemes, a secret (enc/dec)ryption keys are generated for encrypting and decrypting data owned by the client. \n\n"
|
611 |
-
"Additionally, a public evaluation key is generated, enabling external entities to perform homomorphic operations on encrypted data, without the need to decrypt them. \n\n"
|
612 |
-
"The evaluation key will be transmitted to the server for further processing."
|
613 |
)
|
614 |
|
615 |
-
|
616 |
-
error_box2 = gr.Textbox(label="Error β", visible=False)
|
617 |
-
user_id_box = gr.Textbox(label="User ID:", interactive=False, visible=True)
|
618 |
-
key_len_box = gr.Textbox(
|
619 |
-
label="Evaluation Key Size:", interactive=False, visible=False
|
620 |
-
)
|
621 |
-
key_box = gr.Textbox(
|
622 |
-
label="Evaluation key (truncated):",
|
623 |
-
max_lines=3,
|
624 |
-
interactive=False,
|
625 |
-
visible=False,
|
626 |
-
)
|
627 |
|
628 |
-
|
629 |
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
)
|
637 |
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
max_lines=10,
|
648 |
-
interactive=False,
|
649 |
-
)
|
650 |
-
|
651 |
-
encrypt_btn.click(
|
652 |
-
encrypt_fn,
|
653 |
-
inputs=[user_vect_box1, user_id_box],
|
654 |
-
outputs=[
|
655 |
-
user_vect_box2,
|
656 |
-
enc_vect_box,
|
657 |
-
error_box3,
|
658 |
-
],
|
659 |
-
)
|
660 |
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
665 |
|
666 |
-
|
667 |
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
)
|
681 |
|
682 |
-
with gr.
|
683 |
-
gr.
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
"This server employs a [logistic regression]() model that has been trained on this [data-set](https://github.com/anujdutt9/Disease-Prediction-from-Symptoms/tree/master/dataset)."
|
688 |
)
|
689 |
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
|
|
|
|
|
|
|
|
695 |
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
700 |
)
|
701 |
|
702 |
-
|
703 |
-
|
704 |
-
|
|
|
|
|
705 |
|
706 |
-
|
707 |
|
708 |
-
|
|
|
|
|
|
|
|
|
|
|
709 |
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
label="Data Received", show_label=False, interactive=False
|
716 |
-
)
|
717 |
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
|
724 |
-
|
725 |
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
|
|
731 |
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
|
|
|
|
736 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
737 |
|
|
|
|
|
738 |
gr.Markdown(
|
739 |
"""The app was built with [Concrete ML](https://github.com/zama-ai/concrete-ml), a Privacy-Preserving Machine Learning (PPML) open-source set of tools by Zama.
|
740 |
Try it yourself and don't forget to star on [Github](https://github.com/zama-ai/concrete-ml) β.
|
741 |
""")
|
742 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
743 |
gen_key_btn.click(
|
744 |
key_gen_fn,
|
745 |
inputs=user_vect_box1,
|
@@ -751,12 +761,6 @@ if __name__ == "__main__":
|
|
751 |
],
|
752 |
)
|
753 |
|
754 |
-
submit_button.click(
|
755 |
-
fn=get_features_fn,
|
756 |
-
inputs=[*check_boxes],
|
757 |
-
outputs=[user_vect_box1, error_box1, submit_button],
|
758 |
-
)
|
759 |
-
|
760 |
clear_button.click(
|
761 |
reset_fn,
|
762 |
outputs=[
|
|
|
550 |
"Disclaimer: this demo is not to be used as a substitute for medical advice, diagnosis or treatment of any health condition. Any questions regarding your own health should be addressed to your physician or other healthcare provider."
|
551 |
)
|
552 |
|
553 |
+
# ------------------------- Step 1 -------------------------
|
554 |
+
gr.Markdown(
|
555 |
+
"## Step 1: Select chief complaints"
|
556 |
+
)
|
557 |
+
gr.Markdown("<span style='color:grey'>Client Side</span>")
|
558 |
+
gr.Markdown("Select at least 5 symptoms from the list below.")
|
559 |
+
|
560 |
+
# Box symptoms
|
561 |
+
check_boxes = []
|
562 |
+
with gr.Row():
|
563 |
+
with gr.Column():
|
564 |
+
for category in SYMPTOMS_LIST[:3]:
|
565 |
+
with gr.Accordion(pretty_print(category.keys()), open=False):
|
566 |
+
check_box = gr.CheckboxGroup( pretty_print(category.values()), show_label=False)
|
567 |
+
check_boxes.append(check_box)
|
568 |
+
with gr.Column():
|
569 |
+
for category in SYMPTOMS_LIST[3:6]:
|
570 |
+
with gr.Accordion(pretty_print(category.keys()), open=False):
|
571 |
+
check_box = gr.CheckboxGroup( pretty_print(category.values()), show_label=False)
|
572 |
+
check_boxes.append(check_box)
|
573 |
+
with gr.Column():
|
574 |
+
for category in SYMPTOMS_LIST[6:]:
|
575 |
+
with gr.Accordion(pretty_print(category.keys()), open=False):
|
576 |
+
check_box = gr.CheckboxGroup( pretty_print(category.values()), show_label=False)
|
577 |
+
check_boxes.append(check_box)
|
578 |
+
|
579 |
+
error_box1 = gr.Textbox(label="Error β", visible=False)
|
580 |
+
|
581 |
+
# Default disease, picked from the dataframe
|
582 |
+
gr.Markdown("You can choose an **existing disease** and explore its associated symptoms.")
|
583 |
+
|
584 |
+
with gr.Row():
|
585 |
+
with gr.Column(scale=2):
|
586 |
+
disease_box = gr.Dropdown(sorted(diseases), label="Diseases π")
|
587 |
+
with gr.Column(scale=5):
|
588 |
+
default_symptoms = gr.Textbox(
|
589 |
+
label="Related Symptoms:", visible=True, interactive=False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
590 |
)
|
591 |
|
592 |
+
disease_box.change(fn=display_default_symptoms_fn, inputs=[disease_box], outputs=[default_symptoms])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
593 |
|
594 |
+
user_vect_box1 = gr.Textbox(visible=False)
|
595 |
|
596 |
+
with gr.Row():
|
597 |
+
with gr.Column():
|
598 |
+
# Submit botton
|
599 |
+
submit_button = gr.Button("Submit Symptoms π")
|
600 |
+
with gr.Column():
|
601 |
+
# Clear botton
|
602 |
+
clear_button = gr.Button("Reset Space π")
|
603 |
|
604 |
+
# ------------------------- Step 2 -------------------------
|
605 |
+
gr.Markdown("## Step 2: Encrypt data")
|
606 |
+
gr.Markdown("<span style='color:grey'>Client Side</span>")
|
607 |
+
gr.Markdown("### Key Generation")
|
608 |
+
gr.Markdown(
|
609 |
+
"In FHE schemes, a secret (enc/dec)ryption keys are generated for encrypting and decrypting data owned by the client. \n\n"
|
610 |
+
"Additionally, a public evaluation key is generated, enabling external entities to perform homomorphic operations on encrypted data, without the need to decrypt them. \n\n"
|
611 |
+
"The evaluation key will be transmitted to the server for further processing."
|
612 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
613 |
|
614 |
+
gen_key_btn = gr.Button("Generate the evaluation key π")
|
615 |
+
error_box2 = gr.Textbox(label="Error β", visible=False)
|
616 |
+
user_id_box = gr.Textbox(label="User ID:", interactive=False, visible=True)
|
617 |
+
key_len_box = gr.Textbox(
|
618 |
+
label="Evaluation Key Size:", interactive=False, visible=False
|
619 |
+
)
|
620 |
+
key_box = gr.Textbox(
|
621 |
+
label="Evaluation key (truncated):",
|
622 |
+
max_lines=3,
|
623 |
+
interactive=False,
|
624 |
+
visible=False,
|
625 |
+
)
|
626 |
|
627 |
+
gr.Markdown("### Encrypt the data")
|
628 |
|
629 |
+
encrypt_btn = gr.Button("Encrypt the data using the π private secret key π")
|
630 |
+
error_box3 = gr.Textbox(label="Error β", visible=False)
|
631 |
+
quant_vect_box = gr.Textbox(
|
632 |
+
label="Quantized Vector:",
|
633 |
+
interactive=False,
|
634 |
+
visible=False,
|
635 |
+
)
|
636 |
|
637 |
+
with gr.Row():
|
638 |
+
with gr.Column():
|
639 |
+
user_vect_box2 = gr.Textbox(
|
640 |
+
label="User Symptoms Vector:", interactive=False, max_lines=10
|
641 |
)
|
642 |
|
643 |
+
with gr.Column():
|
644 |
+
enc_vect_box = gr.Textbox(
|
645 |
+
label="Encrypted Vector:",
|
646 |
+
max_lines=10,
|
647 |
+
interactive=False,
|
|
|
648 |
)
|
649 |
|
650 |
+
encrypt_btn.click(
|
651 |
+
encrypt_fn,
|
652 |
+
inputs=[user_vect_box1, user_id_box],
|
653 |
+
outputs=[
|
654 |
+
user_vect_box2,
|
655 |
+
enc_vect_box,
|
656 |
+
error_box3,
|
657 |
+
],
|
658 |
+
)
|
659 |
|
660 |
+
gr.Markdown(
|
661 |
+
"### Send the encrypted data to the "
|
662 |
+
"<span style='color:grey'>Server Side</span>"
|
663 |
+
)
|
664 |
+
|
665 |
+
error_box4 = gr.Textbox(label="Error β", visible=False)
|
666 |
+
|
667 |
+
with gr.Row().style(equal_height=False):
|
668 |
+
with gr.Column(scale=4):
|
669 |
+
send_input_btn = gr.Button("Send the encrypted data π")
|
670 |
+
with gr.Column(scale=1):
|
671 |
+
srv_resp_send_data_box = gr.Checkbox(
|
672 |
+
label="Data Sent", show_label=False, interactive=False
|
673 |
)
|
674 |
|
675 |
+
send_input_btn.click(
|
676 |
+
send_input_fn,
|
677 |
+
inputs=[user_id_box, user_vect_box1],
|
678 |
+
outputs=[error_box4, srv_resp_send_data_box],
|
679 |
+
)
|
680 |
|
681 |
+
# ------------------------- Step 3 -------------------------
|
682 |
|
683 |
+
gr.Markdown("## Step 3: Run the FHE evaluation")
|
684 |
+
gr.Markdown("<span style='color:grey'>Server Side</span>")
|
685 |
+
gr.Markdown(
|
686 |
+
"Once the server receives the encrypted data, it can process and compute the output without ever decrypting the data just as it would on clear data.\n\n"
|
687 |
+
"This server employs a [logistic regression]() model that has been trained on this [data-set](https://github.com/anujdutt9/Disease-Prediction-from-Symptoms/tree/master/dataset)."
|
688 |
+
)
|
689 |
|
690 |
+
run_fhe_btn = gr.Button("Run the FHE evaluation π")
|
691 |
+
error_box5 = gr.Textbox(label="Error β", visible=False)
|
692 |
+
fhe_execution_time_box = gr.Textbox(
|
693 |
+
label="Total FHE Execution Time:", interactive=False, visible=True
|
694 |
+
)
|
|
|
|
|
695 |
|
696 |
+
run_fhe_btn.click(
|
697 |
+
run_fhe_fn,
|
698 |
+
inputs=[user_id_box],
|
699 |
+
outputs=[fhe_execution_time_box, error_box5],
|
700 |
+
)
|
701 |
|
702 |
+
# ------------------------- Step 4 -------------------------
|
703 |
|
704 |
+
gr.Markdown("## Step 4: Decrypt the data")
|
705 |
+
gr.Markdown("<span style='color:grey'>Client Side</span>")
|
706 |
+
|
707 |
+
gr.Markdown("### Get the data from the <span style='color:grey'>Server Side</span>")
|
708 |
+
|
709 |
+
error_box6 = gr.Textbox(label="Error β", visible=False)
|
710 |
|
711 |
+
with gr.Row().style(equal_height=True):
|
712 |
+
with gr.Column(scale=4):
|
713 |
+
get_output_btn = gr.Button("Get data π")
|
714 |
+
with gr.Column(scale=1):
|
715 |
+
srv_resp_retrieve_data_box = gr.Checkbox(
|
716 |
+
label="Data Received", show_label=False, interactive=False
|
717 |
)
|
718 |
+
|
719 |
+
get_output_btn.click(
|
720 |
+
get_output_fn,
|
721 |
+
inputs=[user_id_box, user_vect_box1],
|
722 |
+
outputs=[srv_resp_retrieve_data_box, error_box6],
|
723 |
+
)
|
724 |
+
|
725 |
+
gr.Markdown("### Decrypt the output")
|
726 |
+
|
727 |
+
decrypt_target_btn = gr.Button(
|
728 |
+
"Decrypt the output with the π private secret decryption key π"
|
729 |
+
)
|
730 |
+
error_box7 = gr.Textbox(label="Error β", visible=False)
|
731 |
+
decrypt_target_box = gr.Textbox(label="Decrypted Output:", interactive=False)
|
732 |
+
|
733 |
+
decrypt_target_btn.click(
|
734 |
+
decrypt_fn,
|
735 |
+
inputs=[user_id_box, user_vect_box1, *check_boxes],
|
736 |
+
outputs=[decrypt_target_box, error_box7],
|
737 |
+
)
|
738 |
|
739 |
+
# ------------------------- End -------------------------
|
740 |
+
|
741 |
gr.Markdown(
|
742 |
"""The app was built with [Concrete ML](https://github.com/zama-ai/concrete-ml), a Privacy-Preserving Machine Learning (PPML) open-source set of tools by Zama.
|
743 |
Try it yourself and don't forget to star on [Github](https://github.com/zama-ai/concrete-ml) β.
|
744 |
""")
|
745 |
|
746 |
+
|
747 |
+
submit_button.click(
|
748 |
+
fn=get_features_fn,
|
749 |
+
inputs=[*check_boxes],
|
750 |
+
outputs=[user_vect_box1, error_box1, submit_button],
|
751 |
+
)
|
752 |
+
|
753 |
gen_key_btn.click(
|
754 |
key_gen_fn,
|
755 |
inputs=user_vect_box1,
|
|
|
761 |
],
|
762 |
)
|
763 |
|
|
|
|
|
|
|
|
|
|
|
|
|
764 |
clear_button.click(
|
765 |
reset_fn,
|
766 |
outputs=[
|