chore: switch tabs and force the user to provide at least n symptoms
Browse files
app.py
CHANGED
@@ -111,10 +111,17 @@ def get_features_fn(*checked_symptoms: Tuple[str]) -> Dict:
|
|
111 |
),
|
112 |
}
|
113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
return {
|
115 |
error_box1: gr.update(visible=False),
|
116 |
user_vect_box1: get_user_symptoms_from_checkboxgroup(pretty_print(checked_symptoms)),
|
117 |
-
next_step_tab2: gr.update(visible=True),
|
118 |
}
|
119 |
|
120 |
|
@@ -270,7 +277,6 @@ def send_input_fn(user_id: str, user_symptoms: np.ndarray) -> Dict:
|
|
270 |
print(f"Sending Data: {response.ok=}")
|
271 |
return {
|
272 |
error_box4: gr.update(visible=False),
|
273 |
-
next_step_tab3: gr.update(visible=True),
|
274 |
srv_resp_send_data_box: "Data sent",
|
275 |
}
|
276 |
|
@@ -407,6 +413,9 @@ def decrypt_fn(user_id: str, user_symptoms: np.ndarray) -> Dict:
|
|
407 |
# Deserialize, decrypt and post-process the encrypted output
|
408 |
output = client.deserialize_decrypt_dequantize(encrypted_output)
|
409 |
|
|
|
|
|
|
|
410 |
return {
|
411 |
error_box7: gr.update(visible=False),
|
412 |
decrypt_target_box: get_disease_name(output.argmax()),
|
@@ -444,14 +453,19 @@ def reset_fn():
|
|
444 |
**{box: None for box in check_boxes},
|
445 |
}
|
446 |
|
|
|
|
|
|
|
447 |
|
448 |
CSS = """
|
449 |
-
#them {color:
|
450 |
-
#them {font-size: 25px}
|
451 |
-
#them {font-weight: bold}
|
452 |
.gradio-container {background-color: white}
|
453 |
-
.feedback {font-size: 3px !important}
|
454 |
-
|
|
|
|
|
455 |
/* #them {text-align: center} */
|
456 |
"""
|
457 |
|
@@ -490,8 +504,8 @@ if __name__ == "__main__":
|
|
490 |
"""
|
491 |
)
|
492 |
|
493 |
-
with gr.Tabs(
|
494 |
-
with gr.TabItem("1. Symptoms Selection")
|
495 |
gr.Markdown("<span style='color:orange'>Client Side</span>")
|
496 |
gr.Markdown("## Step 1: Provide your symptoms")
|
497 |
gr.Markdown(
|
@@ -533,25 +547,19 @@ if __name__ == "__main__":
|
|
533 |
# Submit botton
|
534 |
submit_button = gr.Button("Submit")
|
535 |
|
536 |
-
# Clear botton
|
537 |
-
clear_button = gr.Button("Reset Space")
|
538 |
-
|
539 |
-
next_step_tab2 = gr.Markdown(
|
540 |
-
"""
|
541 |
-
<p align="center">
|
542 |
-
<img width="80%" height="20%" src="https://raw.githubusercontent.com/kcelia/Img/main/Go-To-Step2.png">
|
543 |
-
</p>
|
544 |
-
""",
|
545 |
-
visible=False,
|
546 |
-
)
|
547 |
-
|
548 |
submit_button.click(
|
549 |
fn=get_features_fn,
|
550 |
inputs=[*check_boxes],
|
551 |
-
outputs=[user_vect_box1, error_box1
|
552 |
)
|
553 |
|
554 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
555 |
gr.Markdown("<span style='color:orange'>Client Side</span>")
|
556 |
gr.Markdown("## Step 2: Generate the keys")
|
557 |
|
@@ -590,6 +598,7 @@ if __name__ == "__main__":
|
|
590 |
encrypt_btn = gr.Button("Encrypt the symptoms with the private key")
|
591 |
error_box3 = gr.Textbox(label="Error", visible=False)
|
592 |
|
|
|
593 |
with gr.Row():
|
594 |
with gr.Column(scale=1, min_width=600):
|
595 |
user_vect_box2 = gr.Textbox(
|
@@ -630,22 +639,24 @@ if __name__ == "__main__":
|
|
630 |
label="Data Sent", show_label=False, interactive=False
|
631 |
)
|
632 |
|
633 |
-
next_step_tab3 = gr.Markdown(
|
634 |
-
"""
|
635 |
-
<p align="center">
|
636 |
-
<img width="80%" height="20%" src="https://raw.githubusercontent.com/kcelia/Img/main/Go-To-Step3.png">
|
637 |
-
</p>
|
638 |
-
""",
|
639 |
-
visible=False,
|
640 |
-
)
|
641 |
-
|
642 |
send_input_btn.click(
|
643 |
send_input_fn,
|
644 |
inputs=[user_id_box, user_vect_box1],
|
645 |
-
outputs=[error_box4, srv_resp_send_data_box
|
646 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
647 |
|
648 |
-
with gr.TabItem("3. FHE execution")
|
649 |
gr.Markdown("<span style='color:orange'>Server Side</span>")
|
650 |
gr.Markdown("## Step 5: Run the FHE evaluation")
|
651 |
|
@@ -655,21 +666,24 @@ if __name__ == "__main__":
|
|
655 |
label="Total FHE Execution Time:", interactive=False
|
656 |
)
|
657 |
|
658 |
-
next_step_tab4 = gr.Markdown(
|
659 |
-
"""
|
660 |
-
<p align="center">
|
661 |
-
<img width="80%" height="20%" src="https://raw.githubusercontent.com/kcelia/Img/main/Go-to-Step4.png">
|
662 |
-
</p>
|
663 |
-
""",
|
664 |
-
visible=False,
|
665 |
-
)
|
666 |
run_fhe_btn.click(
|
667 |
run_fhe_fn,
|
668 |
inputs=[user_id_box],
|
669 |
-
outputs=[fhe_execution_time_box, error_box5
|
670 |
)
|
671 |
|
672 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
673 |
gr.Markdown("<span style='color:orange'>Client Side</span>")
|
674 |
gr.Markdown(
|
675 |
"## Step 6: Get the data from the <span style='color:orange'>Server Side</span>"
|
@@ -703,14 +717,13 @@ if __name__ == "__main__":
|
|
703 |
outputs=[decrypt_target_box, error_box7],
|
704 |
)
|
705 |
|
|
|
|
|
|
|
706 |
clear_button.click(
|
707 |
reset_fn,
|
708 |
outputs=[
|
709 |
-
|
710 |
-
next_step_tab3,
|
711 |
-
next_step_tab4,
|
712 |
-
user_vect_box1,
|
713 |
-
user_vect_box2,
|
714 |
# disease_box,
|
715 |
error_box1,
|
716 |
error_box2,
|
|
|
111 |
),
|
112 |
}
|
113 |
|
114 |
+
if len(pretty_print(checked_symptoms)) < 5:
|
115 |
+
print("Provide at least 5 symptoms.")
|
116 |
+
return {
|
117 |
+
error_box1: gr.update(visible=True, value="Provide at least 5 symptoms"),
|
118 |
+
user_vect_box1: get_user_symptoms_from_checkboxgroup([]),
|
119 |
+
}
|
120 |
+
|
121 |
+
|
122 |
return {
|
123 |
error_box1: gr.update(visible=False),
|
124 |
user_vect_box1: get_user_symptoms_from_checkboxgroup(pretty_print(checked_symptoms)),
|
|
|
125 |
}
|
126 |
|
127 |
|
|
|
277 |
print(f"Sending Data: {response.ok=}")
|
278 |
return {
|
279 |
error_box4: gr.update(visible=False),
|
|
|
280 |
srv_resp_send_data_box: "Data sent",
|
281 |
}
|
282 |
|
|
|
413 |
# Deserialize, decrypt and post-process the encrypted output
|
414 |
output = client.deserialize_decrypt_dequantize(encrypted_output)
|
415 |
|
416 |
+
|
417 |
+
print(output)
|
418 |
+
|
419 |
return {
|
420 |
error_box7: gr.update(visible=False),
|
421 |
decrypt_target_box: get_disease_name(output.argmax()),
|
|
|
453 |
**{box: None for box in check_boxes},
|
454 |
}
|
455 |
|
456 |
+
def change_tab(next_tab):
|
457 |
+
print(next_tab)
|
458 |
+
return gr.Tabs.update(selected=next_tab)
|
459 |
|
460 |
CSS = """
|
461 |
+
/* #them {color: dark-yellow} */
|
462 |
+
/* #them {font-size: 25px} */
|
463 |
+
/* #them {font-weight: bold} */
|
464 |
.gradio-container {background-color: white}
|
465 |
+
/* .feedback {font-size: 3px !important} */
|
466 |
+
#svelte-s1r2yt {color: orange}
|
467 |
+
#svelte-s1r2yt {font-size: 25px}
|
468 |
+
#svelte-s1r2yt {font-weight: bold}
|
469 |
/* #them {text-align: center} */
|
470 |
"""
|
471 |
|
|
|
504 |
"""
|
505 |
)
|
506 |
|
507 |
+
with gr.Tabs(eelem_id ="svelte-s1r2yt", lem_classes="svelte-s1r2yt") as tabs:
|
508 |
+
with gr.TabItem("1. Symptoms Selection", id=0):
|
509 |
gr.Markdown("<span style='color:orange'>Client Side</span>")
|
510 |
gr.Markdown("## Step 1: Provide your symptoms")
|
511 |
gr.Markdown(
|
|
|
547 |
# Submit botton
|
548 |
submit_button = gr.Button("Submit")
|
549 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
550 |
submit_button.click(
|
551 |
fn=get_features_fn,
|
552 |
inputs=[*check_boxes],
|
553 |
+
outputs=[user_vect_box1, error_box1],
|
554 |
)
|
555 |
|
556 |
+
# Clear botton
|
557 |
+
clear_button = gr.Button("Reset Space")
|
558 |
+
|
559 |
+
next_tab = gr.Button('Next Step')
|
560 |
+
next_tab.click(lambda _:gr.Tabs.update(selected=1), None, tabs)
|
561 |
+
|
562 |
+
with gr.TabItem("2. Data Encryption", id=1):
|
563 |
gr.Markdown("<span style='color:orange'>Client Side</span>")
|
564 |
gr.Markdown("## Step 2: Generate the keys")
|
565 |
|
|
|
598 |
encrypt_btn = gr.Button("Encrypt the symptoms with the private key")
|
599 |
error_box3 = gr.Textbox(label="Error", visible=False)
|
600 |
|
601 |
+
|
602 |
with gr.Row():
|
603 |
with gr.Column(scale=1, min_width=600):
|
604 |
user_vect_box2 = gr.Textbox(
|
|
|
639 |
label="Data Sent", show_label=False, interactive=False
|
640 |
)
|
641 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
642 |
send_input_btn.click(
|
643 |
send_input_fn,
|
644 |
inputs=[user_id_box, user_vect_box1],
|
645 |
+
outputs=[error_box4, srv_resp_send_data_box],
|
646 |
)
|
647 |
+
|
648 |
+
with gr.Row().style(equal_height=True):
|
649 |
+
with gr.Column(scale=1):
|
650 |
+
prev_tab = gr.Button('Previous Step')
|
651 |
+
prev_tab.click(lambda _:gr.Tabs.update(selected=0), None, tabs)
|
652 |
+
|
653 |
+
with gr.Column(scale=1):
|
654 |
+
next_tab = gr.Button('Next Step')
|
655 |
+
next_tab.click(lambda _:gr.Tabs.update(selected=2), None, tabs)
|
656 |
+
|
657 |
+
|
658 |
|
659 |
+
with gr.TabItem("3. FHE execution", id=2):
|
660 |
gr.Markdown("<span style='color:orange'>Server Side</span>")
|
661 |
gr.Markdown("## Step 5: Run the FHE evaluation")
|
662 |
|
|
|
666 |
label="Total FHE Execution Time:", interactive=False
|
667 |
)
|
668 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
669 |
run_fhe_btn.click(
|
670 |
run_fhe_fn,
|
671 |
inputs=[user_id_box],
|
672 |
+
outputs=[fhe_execution_time_box, error_box5],
|
673 |
)
|
674 |
|
675 |
+
with gr.Row().style(equal_height=True):
|
676 |
+
with gr.Column(scale=1):
|
677 |
+
prev_tab = gr.Button('Previous Step')
|
678 |
+
prev_tab.click(lambda _: gr.Tabs.update(selected=1), None, tabs)
|
679 |
+
|
680 |
+
with gr.Column(scale=1):
|
681 |
+
next_tab = gr.Button('Next Step')
|
682 |
+
next_tab.click(lambda _: gr.Tabs.update(selected=3), None, tabs)
|
683 |
+
|
684 |
+
|
685 |
+
|
686 |
+
with gr.TabItem("4. Data Decryption", id=3):
|
687 |
gr.Markdown("<span style='color:orange'>Client Side</span>")
|
688 |
gr.Markdown(
|
689 |
"## Step 6: Get the data from the <span style='color:orange'>Server Side</span>"
|
|
|
717 |
outputs=[decrypt_target_box, error_box7],
|
718 |
)
|
719 |
|
720 |
+
prev_tab = gr.Button('Previous Step')
|
721 |
+
prev_tab.click(lambda _:gr.Tabs.update(selected=2), None, tabs)
|
722 |
+
|
723 |
clear_button.click(
|
724 |
reset_fn,
|
725 |
outputs=[
|
726 |
+
|
|
|
|
|
|
|
|
|
727 |
# disease_box,
|
728 |
error_box1,
|
729 |
error_box2,
|