Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -521,7 +521,6 @@ with demo:
|
|
| 521 |
"""
|
| 522 |
<p align="center" style="font-size: 16px;">
|
| 523 |
Anonymization makes it impossible to identify a person from a data set and thus allows their privacy to be respected </p> Concealing some of PII information is a helpful technique for de-identification. However, this can't be considered as anonymization.
|
| 524 |
-
|
| 525 |
<p align="center" style="font-size: 16px;">
|
| 526 |
De-identification uses Fully Homomorphic Encryption (FHE) to conceal personally
|
| 527 |
identifiable information (PII) within encrypted documents, enabling computations to be
|
|
@@ -561,12 +560,9 @@ with demo:
|
|
| 561 |
with gr.Row():
|
| 562 |
audio_recorder = gr.Audio(source="microphone", type="file", label="Record Audio")
|
| 563 |
record_output = gr.Audio(label="Recorded Audio", type="filepath")
|
| 564 |
-
|
| 565 |
# When the user records an audio, save it
|
| 566 |
audio_recorder.change(fn=save_recorded_audio, inputs=[audio_recorder], outputs=[record_output])
|
| 567 |
-
|
| 568 |
gen_key_btn = gr.Button("Generate the secret and evaluation keys")
|
| 569 |
-
|
| 570 |
gen_key_btn.click(
|
| 571 |
key_gen_fn,
|
| 572 |
inputs=[],
|
|
@@ -617,32 +613,32 @@ with demo:
|
|
| 617 |
outputs=[gen_key_btn],
|
| 618 |
)
|
| 619 |
|
| 620 |
-
|
| 621 |
|
| 622 |
-
|
| 623 |
-
|
| 624 |
-
|
| 625 |
-
|
| 626 |
-
|
| 627 |
-
|
| 628 |
|
| 629 |
-
|
| 630 |
-
|
| 631 |
-
|
| 632 |
-
|
| 633 |
-
|
| 634 |
-
|
| 635 |
-
|
| 636 |
-
|
| 637 |
|
| 638 |
-
|
| 639 |
-
|
| 640 |
-
|
| 641 |
|
| 642 |
-
|
| 643 |
-
|
| 644 |
-
|
| 645 |
-
|
| 646 |
|
| 647 |
|
| 648 |
########################## User Query Part ##########################
|
|
@@ -659,13 +655,13 @@ with demo:
|
|
| 659 |
|
| 660 |
with gr.Column(scale=5):
|
| 661 |
default_query_box = gr.Dropdown(
|
| 662 |
-
list(DEFAULT_QUERIES.values()), label="PROMPT"
|
| 663 |
)
|
| 664 |
|
| 665 |
gr.Markdown("Or")
|
| 666 |
|
| 667 |
query_box = gr.Textbox(
|
| 668 |
-
value=
|
| 669 |
)
|
| 670 |
|
| 671 |
default_query_box.change(
|
|
@@ -686,24 +682,40 @@ with demo:
|
|
| 686 |
)
|
| 687 |
|
| 688 |
########################## FHE processing Part ##########################
|
|
|
|
| 689 |
gr.Markdown("<hr />")
|
| 690 |
-
gr.Markdown("## Step 3: De-identify the prompt using FHE")
|
| 691 |
gr.Markdown(
|
| 692 |
-
"""Once the client encrypts the prompt locally, it will be sent to a remote
|
| 693 |
server to perform the de-identification on encrypted data. When the computation is done, the
|
| 694 |
server will return the result to the client for decryption."""
|
|
|
|
| 695 |
)
|
| 696 |
|
| 697 |
run_fhe_btn = gr.Button("De-identify using FHE")
|
| 698 |
|
| 699 |
with gr.Row():
|
| 700 |
with gr.Column(scale=5):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 701 |
anonymized_query_output = gr.Textbox(
|
| 702 |
label="Decrypted and de-identified prompt", lines=10, interactive=True
|
| 703 |
)
|
| 704 |
-
|
|
|
|
| 705 |
identified_words_output_df = gr.Dataframe(label="Identified words:", visible=False)
|
| 706 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 707 |
encrypt_query_btn.click(
|
| 708 |
fn=encrypt_query_fn,
|
| 709 |
inputs=[query_box],
|
|
@@ -717,9 +729,10 @@ with demo:
|
|
| 717 |
|
| 718 |
run_fhe_btn.click(
|
| 719 |
anonymization_with_fn,
|
| 720 |
-
inputs=[query_box],
|
| 721 |
-
outputs=[anonymized_query_output, identified_words_output_df],
|
| 722 |
)
|
|
|
|
| 723 |
|
| 724 |
########################## Presidio ##########################
|
| 725 |
gr.Markdown("<hr />")
|
|
@@ -744,4 +757,4 @@ with demo:
|
|
| 744 |
|
| 745 |
|
| 746 |
# Launch the app
|
| 747 |
-
demo.launch(share=False)
|
|
|
|
| 521 |
"""
|
| 522 |
<p align="center" style="font-size: 16px;">
|
| 523 |
Anonymization makes it impossible to identify a person from a data set and thus allows their privacy to be respected </p> Concealing some of PII information is a helpful technique for de-identification. However, this can't be considered as anonymization.
|
|
|
|
| 524 |
<p align="center" style="font-size: 16px;">
|
| 525 |
De-identification uses Fully Homomorphic Encryption (FHE) to conceal personally
|
| 526 |
identifiable information (PII) within encrypted documents, enabling computations to be
|
|
|
|
| 560 |
with gr.Row():
|
| 561 |
audio_recorder = gr.Audio(source="microphone", type="file", label="Record Audio")
|
| 562 |
record_output = gr.Audio(label="Recorded Audio", type="filepath")
|
|
|
|
| 563 |
# When the user records an audio, save it
|
| 564 |
audio_recorder.change(fn=save_recorded_audio, inputs=[audio_recorder], outputs=[record_output])
|
|
|
|
| 565 |
gen_key_btn = gr.Button("Generate the secret and evaluation keys")
|
|
|
|
| 566 |
gen_key_btn.click(
|
| 567 |
key_gen_fn,
|
| 568 |
inputs=[],
|
|
|
|
| 613 |
outputs=[gen_key_btn],
|
| 614 |
)
|
| 615 |
|
| 616 |
+
########################## Main document Part ##########################
|
| 617 |
|
| 618 |
+
gr.Markdown("<hr />")
|
| 619 |
+
gr.Markdown("## Step 2.1: Select the document you want to encrypt\n\n"
|
| 620 |
+
"""To make it simple, we pre-compiled the following document, but you are free to choose
|
| 621 |
+
on which part you want to run this example.
|
| 622 |
+
"""
|
| 623 |
+
)
|
| 624 |
|
| 625 |
+
with gr.Row():
|
| 626 |
+
with gr.Column(scale=5):
|
| 627 |
+
original_sentences_box = gr.CheckboxGroup(
|
| 628 |
+
ORIGINAL_DOCUMENT,
|
| 629 |
+
value=ORIGINAL_DOCUMENT,
|
| 630 |
+
label="Contract:",
|
| 631 |
+
show_label=True,
|
| 632 |
+
)
|
| 633 |
|
| 634 |
+
with gr.Column(scale=1, min_width=6):
|
| 635 |
+
gr.HTML("<div style='height: 77px;'></div>")
|
| 636 |
+
encrypt_doc_btn = gr.Button("Encrypt the document")
|
| 637 |
|
| 638 |
+
with gr.Column(scale=5):
|
| 639 |
+
encrypted_doc_box = gr.Textbox(
|
| 640 |
+
label="Encrypted document:", show_label=True, interactive=False, lines=10
|
| 641 |
+
)
|
| 642 |
|
| 643 |
|
| 644 |
########################## User Query Part ##########################
|
|
|
|
| 655 |
|
| 656 |
with gr.Column(scale=5):
|
| 657 |
default_query_box = gr.Dropdown(
|
| 658 |
+
list(DEFAULT_QUERIES.values()), label="PROMPT EXAMPLES:"
|
| 659 |
)
|
| 660 |
|
| 661 |
gr.Markdown("Or")
|
| 662 |
|
| 663 |
query_box = gr.Textbox(
|
| 664 |
+
value=" Hello. My name is Inuitvementoya. You kill my father. Prepare to die.", label="CUSTOMIZED PROMPT:", interactive=True
|
| 665 |
)
|
| 666 |
|
| 667 |
default_query_box.change(
|
|
|
|
| 682 |
)
|
| 683 |
|
| 684 |
########################## FHE processing Part ##########################
|
| 685 |
+
|
| 686 |
gr.Markdown("<hr />")
|
| 687 |
+
gr.Markdown("## Step 3: De-identify the document and the prompt using FHE")
|
| 688 |
gr.Markdown(
|
| 689 |
+
"""Once the client encrypts the document and the prompt locally, it will be sent to a remote
|
| 690 |
server to perform the de-identification on encrypted data. When the computation is done, the
|
| 691 |
server will return the result to the client for decryption."""
|
| 692 |
+
|
| 693 |
)
|
| 694 |
|
| 695 |
run_fhe_btn = gr.Button("De-identify using FHE")
|
| 696 |
|
| 697 |
with gr.Row():
|
| 698 |
with gr.Column(scale=5):
|
| 699 |
+
|
| 700 |
+
anonymized_doc_output = gr.Textbox(
|
| 701 |
+
label="Decrypted and de-idenntified document", lines=10, interactive=True
|
| 702 |
+
)
|
| 703 |
+
|
| 704 |
+
with gr.Column(scale=5):
|
| 705 |
+
|
| 706 |
anonymized_query_output = gr.Textbox(
|
| 707 |
label="Decrypted and de-identified prompt", lines=10, interactive=True
|
| 708 |
)
|
| 709 |
+
|
| 710 |
+
|
| 711 |
identified_words_output_df = gr.Dataframe(label="Identified words:", visible=False)
|
| 712 |
|
| 713 |
+
encrypt_doc_btn.click(
|
| 714 |
+
fn=encrypt_doc_fn,
|
| 715 |
+
inputs=[original_sentences_box],
|
| 716 |
+
outputs=[encrypted_doc_box, anonymized_doc_output],
|
| 717 |
+
)
|
| 718 |
+
|
| 719 |
encrypt_query_btn.click(
|
| 720 |
fn=encrypt_query_fn,
|
| 721 |
inputs=[query_box],
|
|
|
|
| 729 |
|
| 730 |
run_fhe_btn.click(
|
| 731 |
anonymization_with_fn,
|
| 732 |
+
inputs=[original_sentences_box, query_box],
|
| 733 |
+
outputs=[anonymized_doc_output, anonymized_query_output, identified_words_output_df],
|
| 734 |
)
|
| 735 |
+
|
| 736 |
|
| 737 |
########################## Presidio ##########################
|
| 738 |
gr.Markdown("<hr />")
|
|
|
|
| 757 |
|
| 758 |
|
| 759 |
# Launch the app
|
| 760 |
+
demo.launch(share=False)
|