Spaces:
Sleeping
Sleeping
Commit
·
b160148
1
Parent(s):
628fe8f
update
Browse files- README.md +1 -1
- app.py +16 -8
- fhe_anonymizer.py +1 -0
README.md
CHANGED
|
@@ -15,7 +15,7 @@ tags:
|
|
| 15 |
- data anonymization
|
| 16 |
- homomorphic encryption
|
| 17 |
- security
|
| 18 |
-
python_version: 3.
|
| 19 |
---
|
| 20 |
|
| 21 |
# Data Anonymization using FHE
|
|
|
|
| 15 |
- data anonymization
|
| 16 |
- homomorphic encryption
|
| 17 |
- security
|
| 18 |
+
python_version: 3.10
|
| 19 |
---
|
| 20 |
|
| 21 |
# Data Anonymization using FHE
|
app.py
CHANGED
|
@@ -84,9 +84,10 @@ with open("files/original_document.txt", "r") as file:
|
|
| 84 |
with open("files/anonymized_document.txt", "r") as file:
|
| 85 |
anonymized_document = file.read()
|
| 86 |
|
| 87 |
-
demo = gr.Blocks()
|
| 88 |
|
| 89 |
with demo:
|
|
|
|
| 90 |
gr.Markdown(
|
| 91 |
"""
|
| 92 |
<p align="center">
|
|
@@ -112,11 +113,12 @@ with demo:
|
|
| 112 |
"""
|
| 113 |
)
|
| 114 |
|
| 115 |
-
with gr.
|
| 116 |
-
gr.
|
|
|
|
| 117 |
|
| 118 |
-
|
| 119 |
-
|
| 120 |
|
| 121 |
# gr.Markdown(
|
| 122 |
# """
|
|
@@ -129,14 +131,20 @@ with demo:
|
|
| 129 |
with gr.Row():
|
| 130 |
input_text = gr.Textbox(
|
| 131 |
value=default_demo_text,
|
| 132 |
-
lines=
|
| 133 |
placeholder="Input text here...",
|
| 134 |
label="Input",
|
| 135 |
)
|
| 136 |
|
| 137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
-
identified_words_output = gr.Dataframe(label="Identified Words", visible=
|
| 140 |
|
| 141 |
submit_button = gr.Button("Anonymize with FHE")
|
| 142 |
|
|
|
|
| 84 |
with open("files/anonymized_document.txt", "r") as file:
|
| 85 |
anonymized_document = file.read()
|
| 86 |
|
| 87 |
+
demo = gr.Blocks(css=".markdown-body { font-size: 18px; }")
|
| 88 |
|
| 89 |
with demo:
|
| 90 |
+
|
| 91 |
gr.Markdown(
|
| 92 |
"""
|
| 93 |
<p align="center">
|
|
|
|
| 113 |
"""
|
| 114 |
)
|
| 115 |
|
| 116 |
+
with gr.Row():
|
| 117 |
+
with gr.Accordion("Original Document", open=True):
|
| 118 |
+
gr.Markdown(original_document)
|
| 119 |
|
| 120 |
+
with gr.Accordion("Anonymized Document", open=True):
|
| 121 |
+
gr.Markdown(anonymized_document)
|
| 122 |
|
| 123 |
# gr.Markdown(
|
| 124 |
# """
|
|
|
|
| 131 |
with gr.Row():
|
| 132 |
input_text = gr.Textbox(
|
| 133 |
value=default_demo_text,
|
| 134 |
+
lines=1,
|
| 135 |
placeholder="Input text here...",
|
| 136 |
label="Input",
|
| 137 |
)
|
| 138 |
|
| 139 |
+
# List of example queries for easy access
|
| 140 |
+
example_queries = ["Example Query 1", "Example Query 2", "Example Query 3"]
|
| 141 |
+
examples_radio = gr.Radio(choices=example_queries, label="Example Queries")
|
| 142 |
+
|
| 143 |
+
examples_radio.change(lambda example_query: example_query, inputs=[examples_radio], outputs=[input_text])
|
| 144 |
+
|
| 145 |
+
anonymized_text_output = gr.Textbox(label="Anonymized Text with FHE", lines=1)
|
| 146 |
|
| 147 |
+
identified_words_output = gr.Dataframe(label="Identified Words", visible=False)
|
| 148 |
|
| 149 |
submit_button = gr.Button("Anonymize with FHE")
|
| 150 |
|
fhe_anonymizer.py
CHANGED
|
@@ -56,6 +56,7 @@ class FHEAnonymizer:
|
|
| 56 |
|
| 57 |
if probability >= 0.5:
|
| 58 |
identified_words_with_prob.append((token, probability))
|
|
|
|
| 59 |
# Use the existing UUID if available, otherwise generate a new one
|
| 60 |
tmp_uuid = self.uuid_map.get(token, str(uuid.uuid4())[:8])
|
| 61 |
processed_tokens.append(tmp_uuid)
|
|
|
|
| 56 |
|
| 57 |
if probability >= 0.5:
|
| 58 |
identified_words_with_prob.append((token, probability))
|
| 59 |
+
|
| 60 |
# Use the existing UUID if available, otherwise generate a new one
|
| 61 |
tmp_uuid = self.uuid_map.get(token, str(uuid.uuid4())[:8])
|
| 62 |
processed_tokens.append(tmp_uuid)
|