kcelia commited on
Commit
af10795
β€’
1 Parent(s): f782fe6

chore: update

Browse files
Files changed (2) hide show
  1. app.py +42 -62
  2. utils.py +1 -1
app.py CHANGED
@@ -124,7 +124,7 @@ def get_features_fn(*checked_symptoms: Tuple[str]) -> Dict:
124
  visible=False,
125
  value=get_user_symptoms_from_checkboxgroup(pretty_print(checked_symptoms)),
126
  ),
127
- submit_button: gr.update(value="Data submitted βœ…"),
128
  }
129
 
130
 
@@ -457,7 +457,7 @@ def decrypt_fn(
457
  return {
458
  error_box7: gr.update(visible=False),
459
  decrypt_target_box: out,
460
- submit_button: gr.update(value="Submit")
461
  }
462
 
463
 
@@ -468,7 +468,7 @@ def reset_fn():
468
 
469
  return {
470
  user_vect_box2: None,
471
- submit_button: gr.update(value="Submit"),
472
  user_id_box: gr.update(visible=False, value=None, interactive=False),
473
  user_vect_box1: None,
474
  default_symptoms: gr.update(visible=True, value=None),
@@ -540,7 +540,7 @@ if __name__ == "__main__":
540
  gr.Markdown("<span style='color:grey'>Client Side</span>")
541
  gr.Markdown("Select at least 5 chief complaints from the list below.")
542
 
543
- # Box symptoms
544
  check_boxes = []
545
  with gr.Row():
546
  with gr.Column():
@@ -571,23 +571,29 @@ if __name__ == "__main__":
571
  default_symptoms = gr.Textbox(
572
  label="Related Symptoms:", interactive=False, visible=False,
573
  )
574
-
575
- disease_box.change(fn=display_default_symptoms_fn, inputs=[disease_box], outputs=[default_symptoms])
576
-
577
  user_vect_box1 = gr.Textbox(visible=False)
578
-
579
  # Submit botton
580
- submit_button = gr.Button("Submit")
581
  # Clear botton
582
- clear_button = gr.Button("Reset Space πŸ” ↻", visible=False)
 
 
 
 
 
 
 
 
 
583
 
584
-
585
  # ------------------------- Step 2 -------------------------
586
  gr.Markdown("## Step 2: Encrypt data")
587
  gr.Markdown("<hr />")
588
  gr.Markdown("<span style='color:grey'>Client Side</span>")
589
- gr.Markdown("### Key Generation")
590
  gr.Markdown(
 
591
  "In FHE schemes, a secret (enc/dec)ryption keys are generated for encrypting and decrypting data owned by the client. \n\n"
592
  "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"
593
  "The evaluation key will be transmitted to the server for further processing."
@@ -595,39 +601,32 @@ if __name__ == "__main__":
595
 
596
  gen_key_btn = gr.Button("Generate the evaluation key")
597
  error_box2 = gr.Textbox(label="Error ❌", visible=False)
598
- user_id_box = gr.Textbox(label="User ID:", interactive=False, visible=True)
599
- key_len_box = gr.Textbox(
600
- label="Evaluation Key Size:", interactive=False, visible=False
601
- )
602
- key_box = gr.Textbox(
603
- label="Evaluation key (truncated):",
604
- max_lines=3,
605
- interactive=False,
606
- visible=False,
 
 
 
 
607
  )
608
 
 
609
  gr.Markdown("### Encrypt the data")
610
-
611
  encrypt_btn = gr.Button("Encrypt the data using the private secret key")
612
  error_box3 = gr.Textbox(label="Error ❌", visible=False)
613
- quant_vect_box = gr.Textbox(
614
- label="Quantized Vector:",
615
- interactive=False,
616
- visible=False,
617
- )
618
 
619
  with gr.Row():
620
  with gr.Column():
621
- user_vect_box2 = gr.Textbox(
622
- label="User Symptoms Vector:", interactive=False, max_lines=10
623
- )
624
-
625
  with gr.Column():
626
- enc_vect_box = gr.Textbox(
627
- label="Encrypted Vector:",
628
- max_lines=10,
629
- interactive=False,
630
- )
631
 
632
  encrypt_btn.click(
633
  encrypt_fn,
@@ -638,21 +637,17 @@ if __name__ == "__main__":
638
  error_box3,
639
  ],
640
  )
641
-
642
  gr.Markdown(
643
- "### Send the encrypted data to the "
644
- "<span style='color:grey'>Server Side</span>"
645
  )
646
-
647
  error_box4 = gr.Textbox(label="Error ❌", visible=False)
648
 
649
  with gr.Row().style(equal_height=False):
650
  with gr.Column(scale=4):
651
  send_input_btn = gr.Button("Send data")
652
  with gr.Column(scale=1):
653
- srv_resp_send_data_box = gr.Checkbox(
654
- label="Data Sent", show_label=False, interactive=False
655
- )
656
 
657
  send_input_btn.click(
658
  send_input_fn,
@@ -713,7 +708,7 @@ if __name__ == "__main__":
713
  decrypt_target_btn.click(
714
  decrypt_fn,
715
  inputs=[user_id_box, user_vect_box1, *check_boxes],
716
- outputs=[decrypt_target_box, error_box7, submit_button],
717
  )
718
 
719
  # ------------------------- End -------------------------
@@ -723,35 +718,20 @@ if __name__ == "__main__":
723
  Try it yourself and don't forget to star on [Github](https://github.com/zama-ai/concrete-ml) ⭐.
724
  """)
725
 
 
 
726
  gr.Markdown(
727
  """**Please Note**: This space is intended solely for educational and demonstration purposes.
728
  It should not be considered as a replacement for professional medical counsel, diagnosis, or therapy for any health or related issues.
729
  Any questions or concerns about your individual health should be addressed to your doctor or another qualified healthcare provider.
730
  """)
731
 
732
- submit_button.click(
733
- fn=get_features_fn,
734
- inputs=[*check_boxes],
735
- outputs=[user_vect_box1, error_box1, submit_button],
736
- )
737
-
738
- gen_key_btn.click(
739
- key_gen_fn,
740
- inputs=user_vect_box1,
741
- outputs=[
742
- key_box,
743
- user_id_box,
744
- key_len_box,
745
- error_box2,
746
- ],
747
- )
748
-
749
  clear_button.click(
750
  reset_fn,
751
  outputs=[
752
  user_vect_box2,
753
  user_vect_box1,
754
- submit_button,
755
  # disease_box,
756
  error_box1,
757
  error_box2,
 
124
  visible=False,
125
  value=get_user_symptoms_from_checkboxgroup(pretty_print(checked_symptoms)),
126
  ),
127
+ submit_btn: gr.update(value="Data submitted βœ…"),
128
  }
129
 
130
 
 
457
  return {
458
  error_box7: gr.update(visible=False),
459
  decrypt_target_box: out,
460
+ submit_btn: gr.update(value="Submit")
461
  }
462
 
463
 
 
468
 
469
  return {
470
  user_vect_box2: None,
471
+ submit_btn: gr.update(value="Submit"),
472
  user_id_box: gr.update(visible=False, value=None, interactive=False),
473
  user_vect_box1: None,
474
  default_symptoms: gr.update(visible=True, value=None),
 
540
  gr.Markdown("<span style='color:grey'>Client Side</span>")
541
  gr.Markdown("Select at least 5 chief complaints from the list below.")
542
 
543
+ # Step 1.1: Provide symptoms
544
  check_boxes = []
545
  with gr.Row():
546
  with gr.Column():
 
571
  default_symptoms = gr.Textbox(
572
  label="Related Symptoms:", interactive=False, visible=False,
573
  )
574
+ # User vector symptoms encoded in oneHot representation
 
 
575
  user_vect_box1 = gr.Textbox(visible=False)
 
576
  # Submit botton
577
+ submit_btn = gr.Button("Submit")
578
  # Clear botton
579
+ clear_button = gr.Button("Reset Space πŸ”", visible=False)
580
+
581
+ disease_box.change(fn=display_default_symptoms_fn, inputs=[disease_box], outputs=[default_symptoms])
582
+
583
+
584
+ submit_btn.click(
585
+ fn=get_features_fn,
586
+ inputs=[*check_boxes],
587
+ outputs=[user_vect_box1, error_box1, submit_btn],
588
+ )
589
 
 
590
  # ------------------------- Step 2 -------------------------
591
  gr.Markdown("## Step 2: Encrypt data")
592
  gr.Markdown("<hr />")
593
  gr.Markdown("<span style='color:grey'>Client Side</span>")
594
+ # Step 2.1: Key generation
595
  gr.Markdown(
596
+ "### Key Generation\n\n"
597
  "In FHE schemes, a secret (enc/dec)ryption keys are generated for encrypting and decrypting data owned by the client. \n\n"
598
  "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"
599
  "The evaluation key will be transmitted to the server for further processing."
 
601
 
602
  gen_key_btn = gr.Button("Generate the evaluation key")
603
  error_box2 = gr.Textbox(label="Error ❌", visible=False)
604
+ user_id_box = gr.Textbox(label="User ID:", visible=True)
605
+ key_len_box = gr.Textbox(label="Evaluation Key Size:", visible=False)
606
+ key_box = gr.Textbox(label="Evaluation key (truncated):", max_lines=3, visible=False)
607
+
608
+ gen_key_btn.click(
609
+ key_gen_fn,
610
+ inputs=user_vect_box1,
611
+ outputs=[
612
+ key_box,
613
+ user_id_box,
614
+ key_len_box,
615
+ error_box2,
616
+ ],
617
  )
618
 
619
+ # Step 2.2: Encrypt data locally
620
  gr.Markdown("### Encrypt the data")
 
621
  encrypt_btn = gr.Button("Encrypt the data using the private secret key")
622
  error_box3 = gr.Textbox(label="Error ❌", visible=False)
623
+ quant_vect_box = gr.Textbox(label="Quantized Vector:", visible=False)
 
 
 
 
624
 
625
  with gr.Row():
626
  with gr.Column():
627
+ user_vect_box2 = 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,
 
637
  error_box3,
638
  ],
639
  )
640
+ # Step 2.3: Send encrypted data to the server
641
  gr.Markdown(
642
+ "### Send the encrypted data to the <span style='color:grey'>Server Side</span>"
 
643
  )
 
644
  error_box4 = gr.Textbox(label="Error ❌", visible=False)
645
 
646
  with gr.Row().style(equal_height=False):
647
  with gr.Column(scale=4):
648
  send_input_btn = gr.Button("Send data")
649
  with gr.Column(scale=1):
650
+ srv_resp_send_data_box = gr.Checkbox(label="Data Sent", show_label=False)
 
 
651
 
652
  send_input_btn.click(
653
  send_input_fn,
 
708
  decrypt_target_btn.click(
709
  decrypt_fn,
710
  inputs=[user_id_box, user_vect_box1, *check_boxes],
711
+ outputs=[decrypt_target_box, error_box7, submit_btn],
712
  )
713
 
714
  # ------------------------- End -------------------------
 
718
  Try it yourself and don't forget to star on [Github](https://github.com/zama-ai/concrete-ml) ⭐.
719
  """)
720
 
721
+ gr.Markdown("\n\n")
722
+
723
  gr.Markdown(
724
  """**Please Note**: This space is intended solely for educational and demonstration purposes.
725
  It should not be considered as a replacement for professional medical counsel, diagnosis, or therapy for any health or related issues.
726
  Any questions or concerns about your individual health should be addressed to your doctor or another qualified healthcare provider.
727
  """)
728
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
729
  clear_button.click(
730
  reset_fn,
731
  outputs=[
732
  user_vect_box2,
733
  user_vect_box1,
734
+ submit_btn,
735
  # disease_box,
736
  error_box1,
737
  error_box2,
utils.py CHANGED
@@ -10,7 +10,7 @@ from concrete.ml.sklearn import XGBClassifier as ConcreteXGBoostClassifier
10
 
11
  # Max Input to be displayed on the HuggingFace space brower using Gradio
12
  # Too large inputs, slow down the server: https://github.com/gradio-app/gradio/issues/1877
13
- INPUT_BROWSER_LIMIT = 635
14
 
15
  # Store the server's URL
16
  SERVER_URL = "http://localhost:8000/"
 
10
 
11
  # Max Input to be displayed on the HuggingFace space brower using Gradio
12
  # Too large inputs, slow down the server: https://github.com/gradio-app/gradio/issues/1877
13
+ INPUT_BROWSER_LIMIT = 400
14
 
15
  # Store the server's URL
16
  SERVER_URL = "http://localhost:8000/"