Surely99 commited on
Commit
c3ae3a0
·
verified ·
1 Parent(s): 0ec49f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -35
app.py CHANGED
@@ -493,7 +493,7 @@ with demo:
493
 
494
  gr.Markdown(
495
  """
496
- <h1 style="text-align: center;">用全同态加密实现加密匿名化</h1>
497
  """
498
  )
499
 
@@ -522,7 +522,7 @@ with demo:
522
  ########################## Key Gen Part ##########################
523
 
524
  gr.Markdown(
525
- "## 第一步: 生成密钥\n\n"
526
  """在全同态加密 (FHE) 方法中,会创建两种类型的密钥。第一种称为私钥,用于加密和解密用户的数据。第二种称为评估密钥,使服务器能够在不查看实际数据的情况下处理加密数据。
527
  """
528
  )
@@ -538,9 +538,8 @@ with demo:
538
  ########################## Main document Part ##########################
539
 
540
  gr.Markdown("<hr />")
541
- gr.Markdown("## Step 2.1: Select the document you want to encrypt\n\n"
542
- """To make it simple, we pre-compiled the following document, but you are free to choose
543
- on which part you want to run this example.
544
  """
545
  )
546
 
@@ -549,41 +548,40 @@ with demo:
549
  original_sentences_box = gr.CheckboxGroup(
550
  ORIGINAL_DOCUMENT,
551
  value=ORIGINAL_DOCUMENT,
552
- label="Contract:",
553
  show_label=True,
554
  )
555
 
556
  with gr.Column(scale=1, min_width=6):
557
  gr.HTML("<div style='height: 77px;'></div>")
558
- encrypt_doc_btn = gr.Button("Encrypt the document")
559
 
560
  with gr.Column(scale=5):
561
  encrypted_doc_box = gr.Textbox(
562
- label="Encrypted document:", show_label=True, interactive=False, lines=10
563
  )
564
 
565
 
566
  ########################## User Query Part ##########################
567
 
568
  gr.Markdown("<hr />")
569
- gr.Markdown("## Step 2.2: Select the prompt you want to encrypt\n\n"
570
- """Please choose from the predefined options in
571
- <span style='color:grey'>“Prompt examples”</span> or craft a custom question in
572
- the <span style='color:grey'>“Customized prompt”</span> text box.
573
- Remain concise and relevant to the context. Any off-topic query will not be processed.""")
574
 
575
  with gr.Row():
576
  with gr.Column(scale=5):
577
 
578
  with gr.Column(scale=5):
579
  default_query_box = gr.Dropdown(
580
- list(DEFAULT_QUERIES.values()), label="PROMPT EXAMPLES:"
581
  )
582
 
583
- gr.Markdown("Or")
584
 
585
  query_box = gr.Textbox(
586
- value="What is Kate international bank account number?", label="CUSTOMIZED PROMPT:", interactive=True
587
  )
588
 
589
  default_query_box.change(
@@ -594,43 +592,41 @@ with demo:
594
 
595
  with gr.Column(scale=1, min_width=6):
596
  gr.HTML("<div style='height: 77px;'></div>")
597
- encrypt_query_btn = gr.Button("Encrypt the prompt")
598
  # gr.HTML("<div style='height: 50px;'></div>")
599
 
600
  with gr.Column(scale=5):
601
  output_encrypted_box = gr.Textbox(
602
- label="Encrypted anonymized query that will be sent to the anonymization server:",
603
  lines=8,
604
  )
605
 
606
  ########################## FHE processing Part ##########################
607
 
608
  gr.Markdown("<hr />")
609
- gr.Markdown("## Step 3: Anonymize the document and the prompt using FHE")
610
  gr.Markdown(
611
- """Once the client encrypts the document and the prompt locally, it will be sent to a remote
612
- server to perform the anonymization on encrypted data. When the computation is done, the
613
- server will return the result to the client for decryption.
614
  """
615
  )
616
 
617
- run_fhe_btn = gr.Button("Anonymize using FHE")
618
 
619
  with gr.Row():
620
  with gr.Column(scale=5):
621
 
622
  anonymized_doc_output = gr.Textbox(
623
- label="Decrypted and anonymized document", lines=10, interactive=True
624
  )
625
 
626
  with gr.Column(scale=5):
627
 
628
  anonymized_query_output = gr.Textbox(
629
- label="Decrypted and anonymized prompt", lines=10, interactive=True
630
  )
631
 
632
 
633
- identified_words_output_df = gr.Dataframe(label="Identified words:", visible=False)
634
 
635
  encrypt_doc_btn.click(
636
  fn=encrypt_doc_fn,
@@ -658,18 +654,17 @@ with demo:
658
  ########################## ChatGpt Part ##########################
659
 
660
  gr.Markdown("<hr />")
661
- gr.Markdown("## Step 4: Send anonymized prompt to ChatGPT")
662
  gr.Markdown(
663
- """After securely anonymizing the query with FHE,
664
- you can forward it to ChatGPT without having any concern about information leakage."""
665
  )
666
 
667
- chatgpt_button = gr.Button("Query ChatGPT")
668
 
669
  with gr.Row():
670
- chatgpt_response_anonymized = gr.Textbox(label="ChatGPT's anonymized response:", lines=5)
671
  chatgpt_response_deanonymized = gr.Textbox(
672
- label="ChatGPT's non-anonymized response:", lines=5
673
  )
674
 
675
  chatgpt_button.click(
@@ -679,9 +674,8 @@ with demo:
679
  )
680
 
681
  gr.Markdown(
682
- """**Please note**: As this space is intended solely for demonstration purposes, some
683
- private information may be missed during by the anonymization algorithm. Please validate the
684
- following query before sending it to ChatGPT."""
685
  )
686
  # Launch the app
687
  demo.launch(share=False)
 
493
 
494
  gr.Markdown(
495
  """
496
+ <h1 style="text-align: center;">使用全同态加密实现加密匿名化</h1>
497
  """
498
  )
499
 
 
522
  ########################## Key Gen Part ##########################
523
 
524
  gr.Markdown(
525
+ "## 第1步: 生成密钥\n\n"
526
  """在全同态加密 (FHE) 方法中,会创建两种类型的密钥。第一种称为私钥,用于加密和解密用户的数据。第二种称为评估密钥,使服务器能够在不查看实际数据的情况下处理加密数据。
527
  """
528
  )
 
538
  ########################## Main document Part ##########################
539
 
540
  gr.Markdown("<hr />")
541
+ gr.Markdown("## 2.1步: 选择要加密的文档\n\n"
542
+ """为了演示步骤的简单,预先编译了这个文档,但是你可以选择任意部分使用。
 
543
  """
544
  )
545
 
 
548
  original_sentences_box = gr.CheckboxGroup(
549
  ORIGINAL_DOCUMENT,
550
  value=ORIGINAL_DOCUMENT,
551
+ label="合同文件:",
552
  show_label=True,
553
  )
554
 
555
  with gr.Column(scale=1, min_width=6):
556
  gr.HTML("<div style='height: 77px;'></div>")
557
+ encrypt_doc_btn = gr.Button("加密文档")
558
 
559
  with gr.Column(scale=5):
560
  encrypted_doc_box = gr.Textbox(
561
+ label="加密后的文档:", show_label=True, interactive=False, lines=10
562
  )
563
 
564
 
565
  ########################## User Query Part ##########################
566
 
567
  gr.Markdown("<hr />")
568
+ gr.Markdown("## 2.2步: 选择要加密的查询问题\n\n"
569
+ """请从以下预先定义的选择
570
+ <span style='color:grey'>“示例问题”</span>或者输入自己的问题<span style='color:grey'>”输入问题“</span>文本输入框。
571
+ 请保持问题的上下文相关性。任何无关的问题都不会处理。""")
 
572
 
573
  with gr.Row():
574
  with gr.Column(scale=5):
575
 
576
  with gr.Column(scale=5):
577
  default_query_box = gr.Dropdown(
578
+ list(DEFAULT_QUERIES.values()), label="问题示例:"
579
  )
580
 
581
+ gr.Markdown("或者")
582
 
583
  query_box = gr.Textbox(
584
+ value="Kate的国际银行账号是什么?", label="自定义问题:", interactive=True
585
  )
586
 
587
  default_query_box.change(
 
592
 
593
  with gr.Column(scale=1, min_width=6):
594
  gr.HTML("<div style='height: 77px;'></div>")
595
+ encrypt_query_btn = gr.Button("加密的问题")
596
  # gr.HTML("<div style='height: 50px;'></div>")
597
 
598
  with gr.Column(scale=5):
599
  output_encrypted_box = gr.Textbox(
600
+ label="加密后的问题将发送给匿名化服务器:",
601
  lines=8,
602
  )
603
 
604
  ########################## FHE processing Part ##########################
605
 
606
  gr.Markdown("<hr />")
607
+ gr.Markdown("## 3步: 使用全同态加密匿名化文件和问题")
608
  gr.Markdown(
609
+ """客户端在本地对文件和问题进行加密后,会将其发送到远程服务器对加密数据进行匿名化处理。计算完成后,服务器会将结果返回给客户端进行解密。
 
 
610
  """
611
  )
612
 
613
+ run_fhe_btn = gr.Button("使用全同态加密匿名化")
614
 
615
  with gr.Row():
616
  with gr.Column(scale=5):
617
 
618
  anonymized_doc_output = gr.Textbox(
619
+ label="解密和匿名化文件", lines=10, interactive=True
620
  )
621
 
622
  with gr.Column(scale=5):
623
 
624
  anonymized_query_output = gr.Textbox(
625
+ label="解密和匿名化问题", lines=10, interactive=True
626
  )
627
 
628
 
629
+ identified_words_output_df = gr.Dataframe(label="已识别单词:", visible=False)
630
 
631
  encrypt_doc_btn.click(
632
  fn=encrypt_doc_fn,
 
654
  ########################## ChatGpt Part ##########################
655
 
656
  gr.Markdown("<hr />")
657
+ gr.Markdown("## 4步: 发送匿名化后的问题给ChatGPT")
658
  gr.Markdown(
659
+ """使用FHE安全地匿名化查询问题后,您可以将其转发给ChatGPT而不必担心信息泄露。"""
 
660
  )
661
 
662
+ chatgpt_button = gr.Button("查询ChatGPT")
663
 
664
  with gr.Row():
665
+ chatgpt_response_anonymized = gr.Textbox(label="ChatGPT的匿名化响应:", lines=5)
666
  chatgpt_response_deanonymized = gr.Textbox(
667
+ label="ChatGPT的去匿名化响应", lines=5
668
  )
669
 
670
  chatgpt_button.click(
 
674
  )
675
 
676
  gr.Markdown(
677
+ """**请注意**: 由于此应用仅用于演示目的,匿名化算法可能会遗漏一些私人信息。请在将查询发送到ChatGPT之前对其进行复核。
678
+ """
 
679
  )
680
  # Launch the app
681
  demo.launch(share=False)