Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -695,6 +695,87 @@ with demo:
|
|
| 695 |
)
|
| 696 |
|
| 697 |
########################## Presidio ##########################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 698 |
|
| 699 |
# Launch the app
|
| 700 |
demo.launch(share=False)
|
|
|
|
| 695 |
)
|
| 696 |
|
| 697 |
########################## Presidio ##########################
|
| 698 |
+
gr.Markdown("<hr />")
|
| 699 |
+
gr.Markdown("## Step 3: De-identify the document and the prompt")
|
| 700 |
+
gr.Markdown(
|
| 701 |
+
"""This step will demonstrate de-identification using both FHE and Presidio methods.
|
| 702 |
+
The same prompt will be used for both to allow for direct comparison."""
|
| 703 |
+
)
|
| 704 |
+
|
| 705 |
+
with gr.Row():
|
| 706 |
+
with gr.Column(scale=1, min_width=6):
|
| 707 |
+
run_fhe_btn = gr.Button("De-identify using FHE")
|
| 708 |
+
with gr.Column(scale=1, min_width=6):
|
| 709 |
+
run_presidio_btn = gr.Button("De-identify using Presidio")
|
| 710 |
+
with gr.Column(scale=1, min_width=6):
|
| 711 |
+
run_both_btn = gr.Button("Run Both De-identification Methods")
|
| 712 |
+
|
| 713 |
+
with gr.Row():
|
| 714 |
+
with gr.Column(scale=5):
|
| 715 |
+
anonymized_doc_output = gr.Textbox(
|
| 716 |
+
label="FHE: Decrypted and de-identified document", lines=10, interactive=True
|
| 717 |
+
)
|
| 718 |
+
|
| 719 |
+
with gr.Column(scale=5):
|
| 720 |
+
anonymized_query_output = gr.Textbox(
|
| 721 |
+
label="FHE: Decrypted and de-identified prompt", lines=10, interactive=True
|
| 722 |
+
)
|
| 723 |
+
|
| 724 |
+
with gr.Row():
|
| 725 |
+
presidio_output = gr.Textbox(
|
| 726 |
+
label="Presidio: De-identified prompt", lines=10, interactive=True
|
| 727 |
+
)
|
| 728 |
+
|
| 729 |
+
identified_words_output_df = gr.Dataframe(label="FHE: Identified words:", visible=False)
|
| 730 |
+
|
| 731 |
+
encrypt_doc_btn.click(
|
| 732 |
+
fn=encrypt_doc_fn,
|
| 733 |
+
inputs=[original_sentences_box],
|
| 734 |
+
outputs=[encrypted_doc_box, anonymized_doc_output],
|
| 735 |
+
)
|
| 736 |
+
|
| 737 |
+
encrypt_query_btn.click(
|
| 738 |
+
fn=encrypt_query_fn,
|
| 739 |
+
inputs=[query_box],
|
| 740 |
+
outputs=[
|
| 741 |
+
query_box,
|
| 742 |
+
output_encrypted_box,
|
| 743 |
+
anonymized_query_output,
|
| 744 |
+
identified_words_output_df,
|
| 745 |
+
],
|
| 746 |
+
)
|
| 747 |
+
|
| 748 |
+
run_fhe_btn.click(
|
| 749 |
+
anonymization_with_fn,
|
| 750 |
+
inputs=[original_sentences_box, query_box],
|
| 751 |
+
outputs=[anonymized_doc_output, anonymized_query_output, identified_words_output_df],
|
| 752 |
+
)
|
| 753 |
+
|
| 754 |
+
run_presidio_btn.click(
|
| 755 |
+
anonymization_with_presidio,
|
| 756 |
+
inputs=[query_box],
|
| 757 |
+
outputs=[presidio_output],
|
| 758 |
+
)
|
| 759 |
+
|
| 760 |
+
def run_both_deidentification(selected_sentences, query):
|
| 761 |
+
# Run FHE de-identification
|
| 762 |
+
fhe_results = anonymization_with_fn(selected_sentences, query)
|
| 763 |
+
|
| 764 |
+
# Run Presidio de-identification
|
| 765 |
+
presidio_result = anonymization_with_presidio(query)
|
| 766 |
+
|
| 767 |
+
# Combine results
|
| 768 |
+
return {
|
| 769 |
+
**fhe_results,
|
| 770 |
+
'presidio_output': gr.update(value=presidio_result)
|
| 771 |
+
}
|
| 772 |
+
|
| 773 |
+
run_both_btn.click(
|
| 774 |
+
run_both_deidentification,
|
| 775 |
+
inputs=[original_sentences_box, query_box],
|
| 776 |
+
outputs=[anonymized_doc_output, anonymized_query_output, identified_words_output_df, presidio_output],
|
| 777 |
+
)
|
| 778 |
+
|
| 779 |
|
| 780 |
# Launch the app
|
| 781 |
demo.launch(share=False)
|