kcelia commited on
Commit
d7db146
β€’
1 Parent(s): 9c8c3ed

chore: update design in version 6

Browse files
Files changed (1) hide show
  1. app.py +170 -166
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
- with gr.Tabs(eelem_id="them") as tabs:
554
- with gr.TabItem("1. Chief Complaints", id=0):
555
- gr.Markdown(
556
- "## Step 1: Select chief complaints"
557
- )
558
- gr.Markdown("<span style='color:grey'>Client Side</span>")
559
- gr.Markdown("Select at least 5 symptoms from the list below.")
560
-
561
- # Box symptoms
562
- check_boxes = []
563
- with gr.Row():
564
- with gr.Column():
565
- for category in SYMPTOMS_LIST[:3]:
566
- with gr.Accordion(pretty_print(category.keys()), open=False):
567
- check_box = gr.CheckboxGroup( pretty_print(category.values()), show_label=False)
568
- check_boxes.append(check_box)
569
- with gr.Column():
570
- for category in SYMPTOMS_LIST[3:6]:
571
- with gr.Accordion(pretty_print(category.keys()), open=False):
572
- check_box = gr.CheckboxGroup( pretty_print(category.values()), show_label=False)
573
- check_boxes.append(check_box)
574
- with gr.Column():
575
- for category in SYMPTOMS_LIST[6:]:
576
- with gr.Accordion(pretty_print(category.keys()), open=False):
577
- check_box = gr.CheckboxGroup( pretty_print(category.values()), show_label=False)
578
- check_boxes.append(check_box)
579
-
580
- error_box1 = gr.Textbox(label="Error ❌", visible=False)
581
-
582
- # Default disease, picked from the dataframe
583
- gr.Markdown("You can choose an **existing disease** and explore its associated symptoms.")
584
-
585
- with gr.Row():
586
- with gr.Column(scale=2):
587
- disease_box = gr.Dropdown(sorted(diseases), label="Diseases πŸ‘†")
588
- with gr.Column(scale=5):
589
- default_symptoms = gr.Textbox(
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
- gen_key_btn = gr.Button("Generate the evaluation key πŸ‘†")
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
- gr.Markdown("## Encrypt the data")
629
 
630
- encrypt_btn = gr.Button("Encrypt the data using the πŸ”’ private secret key πŸ‘†")
631
- error_box3 = gr.Textbox(label="Error ❌", visible=False)
632
- quant_vect_box = gr.Textbox(
633
- label="Quantized Vector:",
634
- interactive=False,
635
- visible=False,
636
- )
637
 
638
- with gr.Row():
639
- with gr.Column():
640
- user_vect_box2 = gr.Textbox(
641
- label="User Symptoms Vector:", interactive=False, max_lines=10
642
- )
643
-
644
- with gr.Column():
645
- enc_vect_box = gr.Textbox(
646
- label="Encrypted Vector:",
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
- gr.Markdown(
662
- "## Send the encrypted data to the "
663
- "<span style='color:grey'>Server Side</span>"
664
- )
 
 
 
 
 
 
 
 
665
 
666
- error_box4 = gr.Textbox(label="Error ❌", visible=False)
667
 
668
- with gr.Row().style(equal_height=False):
669
- with gr.Column(scale=4):
670
- send_input_btn = gr.Button("Send the encrypted data πŸ‘†")
671
- with gr.Column(scale=1):
672
- srv_resp_send_data_box = gr.Checkbox(
673
- label="Data Sent", show_label=False, interactive=False
674
- )
675
 
676
- send_input_btn.click(
677
- send_input_fn,
678
- inputs=[user_id_box, user_vect_box1],
679
- outputs=[error_box4, srv_resp_send_data_box],
680
  )
681
 
682
- with gr.TabItem("3. FHE execution", id=2):
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
- with gr.TabItem("4. Data Decryption", id=3):
703
- gr.Markdown("## Step 4: Decrypt the data")
704
- gr.Markdown("<span style='color:grey'>Client Side</span>")
 
 
705
 
706
- gr.Markdown("### Get the data from the <span style='color:grey'>Server Side</span>")
707
 
708
- error_box6 = gr.Textbox(label="Error ❌", visible=False)
 
 
 
 
 
709
 
710
- with gr.Row().style(equal_height=True):
711
- with gr.Column(scale=4):
712
- get_output_btn = gr.Button("Get data πŸ‘†")
713
- with gr.Column(scale=1):
714
- srv_resp_retrieve_data_box = gr.Checkbox(
715
- label="Data Received", show_label=False, interactive=False
716
- )
717
 
718
- get_output_btn.click(
719
- get_output_fn,
720
- inputs=[user_id_box, user_vect_box1],
721
- outputs=[srv_resp_retrieve_data_box, error_box6],
722
- )
723
 
724
- gr.Markdown("### Decrypt the output")
725
 
726
- decrypt_target_btn = gr.Button(
727
- "Decrypt the output with the πŸ”’ private secret decryption key πŸ‘†"
728
- )
729
- error_box7 = gr.Textbox(label="Error ❌", visible=False)
730
- decrypt_target_box = gr.Textbox(label="Decrypted Output:", interactive=False)
 
731
 
732
- decrypt_target_btn.click(
733
- decrypt_fn,
734
- inputs=[user_id_box, user_vect_box1, *check_boxes],
735
- outputs=[decrypt_target_box, error_box7],
 
 
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=[