kcelia commited on
Commit
bd20950
1 Parent(s): 174cd37

chore: update

Browse files
Files changed (1) hide show
  1. app.py +52 -47
app.py CHANGED
@@ -96,6 +96,10 @@ def run_fhe_fn(query_box):
96
  anonymizer.run_server_and_decrypt_output(query_box)
97
 
98
  anonymized_text = read_pickle(KEYS_DIR / "reconstructed_sentence")
 
 
 
 
99
  identified_words_with_prob = read_pickle(KEYS_DIR / "identified_words_with_prob")
100
 
101
  # Convert the list of identified words and probabilities into a DataFrame
@@ -203,12 +207,8 @@ with demo:
203
 
204
  with gr.Accordion("What is encrypted anonymization?", open=False):
205
  gr.Markdown(
206
- <<<<<<< HEAD
207
  """
208
  Anonymization is the process of removing personally identifiable information (PII)
209
- =======
210
- """Anonymization is the process of removing personally identifiable information (PII)
211
- >>>>>>> 053bec9 (chore: update with marketing remarks)
212
  from data to protect individual privacy.
213
 
214
  To resolve trust issues when deploying anonymization as a cloud service, Fully Homomorphic
@@ -224,13 +224,15 @@ with demo:
224
  ########################## Key Gen Part ##########################
225
 
226
  gr.Markdown(
227
- "### Key generation\n\n"
228
- """In FHE schemes, two sets of keys are generated. First, secret keys are used for
229
- encrypting and decrypting data owned by the client. Second, evaluation keys allow a server
230
- to blindly process the encrypted data. """
 
 
231
  )
232
 
233
- gen_key_btn = gr.Button("Generate the private and evaluation keys")
234
 
235
  gen_key_btn.click(
236
  key_gen_fn,
@@ -240,33 +242,38 @@ with demo:
240
 
241
  ########################## Main document Part ##########################
242
 
243
- gr.Markdown("## Private document")
 
 
244
 
245
  with gr.Row():
246
  with gr.Column():
 
247
  gr.Markdown(
248
  """This document was retrieved from the [Microsoft Presidio](https://huggingface.co/spaces/presidio/presidio_demo) demo.\n\n
249
  You can select and deselect sentences to customize the document that will be used
250
- as the initial prompt for ChatGPT in this space's final stage.\n\n
251
  """
252
  )
253
  with gr.Column():
 
254
  gr.Markdown(
255
- """You can see the anonymized document that is sent to ChatGPT here.
256
- ChatGPT will answer any queries that you have about the document below.
257
- The anonymized information is replaced with hexadecimal strings.
 
258
  """
259
  )
260
 
261
  with gr.Row():
262
  with gr.Column():
263
  original_sentences_box = gr.CheckboxGroup(
264
- ORIGINAL_DOCUMENT, value=ORIGINAL_DOCUMENT, label="Original document:"
265
  )
266
 
267
  with gr.Column():
268
- anonymized_doc_box = gr.Textbox(
269
- label="Anonymized document:", value=ANONYMIZED_DOCUMENT, interactive=False, lines=11
270
  )
271
 
272
  original_sentences_box.change(
@@ -278,15 +285,14 @@ with demo:
278
  ########################## User Query Part ##########################
279
 
280
  gr.Markdown("<hr />")
281
- gr.Markdown("## Private query")
282
 
283
  gr.Markdown(
284
- """Now, formulate a query regarding the selected document.\n\n
 
285
 
286
- Choose from predefined options in 'Example Queries' or craft a custom query
287
- in the 'User Query' box. Keep your question concise and relevant to the text's
288
- context. Any off-topic question will not be processed.
289
- """
290
  )
291
 
292
  with gr.Row():
@@ -294,11 +300,13 @@ with demo:
294
 
295
  with gr.Column(scale=5):
296
  default_query_box = gr.Dropdown(
297
- list(DEFAULT_QUERIES.values()), label="Example queries"
298
  )
299
 
 
 
300
  query_box = gr.Textbox(
301
- value="Who lives in Maine?", label="User query", interactive=True
302
  )
303
 
304
  default_query_box.change(
@@ -313,40 +321,40 @@ with demo:
313
  gr.Markdown(
314
  """
315
  <p align="center">
316
- Encrypt data locally with FHE 💻 ⚙️
317
  </p>
318
  """
319
  )
320
- encrypt_btn = gr.Button("Encrypt data")
321
  gr.HTML("<div style='height: 25px;'></div>")
322
 
323
  with gr.Column(scale=5):
324
  output_encrypted_box = gr.Textbox(
325
- label="Encrypted anonymized query that is sent to the anonymization server", lines=6
326
  )
327
 
328
  encrypt_btn.click(
329
  fn=encrypt_query_fn, inputs=[query_box], outputs=[query_box, output_encrypted_box]
330
  )
331
 
 
 
332
  gr.Markdown("<hr />")
333
- gr.Markdown("## Secure anonymization with FHE")
334
  gr.Markdown(
335
- """
336
- Once the client encrypts the private query locally,
337
- the client transmits it to a remote server to perform the
338
- anonymization on encrypted data. When the computation is finished, the server returns
339
- the result to the client for decryption.
340
  """
341
  )
342
 
343
  run_fhe_btn = gr.Button("Anonymize with FHE")
344
 
345
  anonymized_text_output = gr.Textbox(
346
- label="Decrypted anonymized query that will be sent to ChatGPT", lines=1, interactive=True
347
  )
348
 
349
- identified_words_output = gr.Dataframe(label="Identified words", visible=False)
350
 
351
  run_fhe_btn.click(
352
  run_fhe_fn,
@@ -354,20 +362,21 @@ with demo:
354
  outputs=[anonymized_text_output, identified_words_output],
355
  )
356
 
357
- gr.Markdown("<hr />")
358
 
359
- gr.Markdown("## Secure your communication on ChatGPT with anonymized queries")
 
360
  gr.Markdown(
361
  """After securely anonymizing the query with FHE,
362
- you can forward it to ChatGPT without any concern for information leakage."""
363
  )
364
 
365
  chatgpt_button = gr.Button("Query ChatGPT")
366
 
367
  with gr.Row():
368
- chatgpt_response_anonymized = gr.Textbox(label="ChatGPT anonymized response", lines=13)
369
  chatgpt_response_deanonymized = gr.Textbox(
370
- label="ChatGPT non-anonymized response", lines=13
371
  )
372
 
373
  chatgpt_button.click(
@@ -377,13 +386,9 @@ with demo:
377
  )
378
 
379
  gr.Markdown(
380
- """**Please Note**: As this space is intended solely for demonstration purposes, some
381
- private information may be missed the the anonymization algorithm. Please validate the
382
  following query before sending it to ChatGPT."""
383
  )
384
- <<<<<<< HEAD
385
- =======
386
-
387
- >>>>>>> 053bec9 (chore: update with marketing remarks)
388
  # Launch the app
389
  demo.launch(share=False)
 
96
  anonymizer.run_server_and_decrypt_output(query_box)
97
 
98
  anonymized_text = read_pickle(KEYS_DIR / "reconstructed_sentence")
99
+
100
+ # Removing Spaces Before Punctuation:
101
+ anonymized_text = re.sub(r"\s([,.!?;:])", r"\1", anonymized_text)
102
+
103
  identified_words_with_prob = read_pickle(KEYS_DIR / "identified_words_with_prob")
104
 
105
  # Convert the list of identified words and probabilities into a DataFrame
 
207
 
208
  with gr.Accordion("What is encrypted anonymization?", open=False):
209
  gr.Markdown(
 
210
  """
211
  Anonymization is the process of removing personally identifiable information (PII)
 
 
 
212
  from data to protect individual privacy.
213
 
214
  To resolve trust issues when deploying anonymization as a cloud service, Fully Homomorphic
 
224
  ########################## Key Gen Part ##########################
225
 
226
  gr.Markdown(
227
+ "## Step 1: Key generation\n\n"
228
+
229
+ """In FHE schemes, two sets of keys are generated. First, the secret keys which are used for
230
+ encrypting and decrypting data owned by the client. Second, the evaluation keys that allow
231
+ a server to blindly process the encrypted data.
232
+ """
233
  )
234
 
235
+ gen_key_btn = gr.Button("Generate the secret and evaluation keys")
236
 
237
  gen_key_btn.click(
238
  key_gen_fn,
 
242
 
243
  ########################## Main document Part ##########################
244
 
245
+ gr.Markdown("## Step 2: Private document")
246
+
247
+
248
 
249
  with gr.Row():
250
  with gr.Column():
251
+ gr.Markdown("**Original document:**")
252
  gr.Markdown(
253
  """This document was retrieved from the [Microsoft Presidio](https://huggingface.co/spaces/presidio/presidio_demo) demo.\n\n
254
  You can select and deselect sentences to customize the document that will be used
255
+ as the initial prompt for ChatGPT in step 5.
256
  """
257
  )
258
  with gr.Column():
259
+ gr.Markdown("**Anonymized document:**")
260
  gr.Markdown(
261
+ """You can see below the anonymized text, replaced with hexademical strings, that
262
+ will be sent to ChatGPT.
263
+
264
+ ChatGPT will then be able to answer any queries about the document.
265
  """
266
  )
267
 
268
  with gr.Row():
269
  with gr.Column():
270
  original_sentences_box = gr.CheckboxGroup(
271
+ ORIGINAL_DOCUMENT, value=ORIGINAL_DOCUMENT, show_label=False,
272
  )
273
 
274
  with gr.Column():
275
+ anonymized_doc_box = gr.Textbox(show_label=False,
276
+ value=ANONYMIZED_DOCUMENT, interactive=False, lines=11
277
  )
278
 
279
  original_sentences_box.change(
 
285
  ########################## User Query Part ##########################
286
 
287
  gr.Markdown("<hr />")
288
+ gr.Markdown("## Step 3: Private query")
289
 
290
  gr.Markdown(
291
+ """Now, you can formulate a query. Please choose from the predefined options in
292
+ “Queries examples” or craft a custom question in the “Customized query” text box.
293
 
294
+ Remain concise and relevant to the context. Any off-topic query will not be processed.
295
+ """
 
 
296
  )
297
 
298
  with gr.Row():
 
300
 
301
  with gr.Column(scale=5):
302
  default_query_box = gr.Dropdown(
303
+ list(DEFAULT_QUERIES.values()), label="Queries examples:"
304
  )
305
 
306
+ gr.Markdown("Or")
307
+
308
  query_box = gr.Textbox(
309
+ value="Who lives in Maine?", label="Customized query:", interactive=True
310
  )
311
 
312
  default_query_box.change(
 
321
  gr.Markdown(
322
  """
323
  <p align="center">
324
+ Encrypt the query locally with FHE
325
  </p>
326
  """
327
  )
328
+ encrypt_btn = gr.Button("Encrypt query”")
329
  gr.HTML("<div style='height: 25px;'></div>")
330
 
331
  with gr.Column(scale=5):
332
  output_encrypted_box = gr.Textbox(
333
+ label="Encrypted anonymized query that will be sent to the anonymization server:", lines=8
334
  )
335
 
336
  encrypt_btn.click(
337
  fn=encrypt_query_fn, inputs=[query_box], outputs=[query_box, output_encrypted_box]
338
  )
339
 
340
+ ########################## FHE processing Part ##########################
341
+
342
  gr.Markdown("<hr />")
343
+ gr.Markdown("## Step 4: Secure anonymization with FHE")
344
  gr.Markdown(
345
+ """ Once the client encrypts the private query locally, it will be sent to a remote server
346
+ to perform the anonymization on encrypted data. When the computation is done, the server
347
+ will return the result to the client for decryption.
 
 
348
  """
349
  )
350
 
351
  run_fhe_btn = gr.Button("Anonymize with FHE")
352
 
353
  anonymized_text_output = gr.Textbox(
354
+ label="Decrypted anonymized query that will be sent to ChatGPT:", lines=1, interactive=True
355
  )
356
 
357
+ identified_words_output = gr.Dataframe(label="Identified words:", visible=False)
358
 
359
  run_fhe_btn.click(
360
  run_fhe_fn,
 
362
  outputs=[anonymized_text_output, identified_words_output],
363
  )
364
 
365
+ ########################## ChatGpt Part ##########################
366
 
367
+ gr.Markdown("<hr />")
368
+ gr.Markdown("## Spet 5: Secure your communication on ChatGPT with anonymized queries")
369
  gr.Markdown(
370
  """After securely anonymizing the query with FHE,
371
+ you can forward it to ChatGPT without having any concern about information leakage."""
372
  )
373
 
374
  chatgpt_button = gr.Button("Query ChatGPT")
375
 
376
  with gr.Row():
377
+ chatgpt_response_anonymized = gr.Textbox(label="ChatGPT's anonymized response:", lines=13)
378
  chatgpt_response_deanonymized = gr.Textbox(
379
+ label="ChatGPT's non-anonymized response:", lines=13
380
  )
381
 
382
  chatgpt_button.click(
 
386
  )
387
 
388
  gr.Markdown(
389
+ """**Please note**: As this space is intended solely for demonstration purposes, some
390
+ private information may be missed during by the anonymization algorithm. Please validate the
391
  following query before sending it to ChatGPT."""
392
  )
 
 
 
 
393
  # Launch the app
394
  demo.launch(share=False)