Pranav Shikarpur commited on
Commit
1110ee8
·
1 Parent(s): 492a45e

feat: updated demo to handle credit card info

Browse files
Files changed (2) hide show
  1. app.py +13 -23
  2. requirements.txt +1 -2
app.py CHANGED
@@ -1,41 +1,31 @@
1
  import gradio as gr
2
  from pangea.services import Redact
3
- import openai
4
 
5
  def redact_input(input: str, pangea_token: str):
6
  redact = Redact(token=pangea_token)
7
  return redact.redact(text=input).result.redacted_text
8
 
9
- def gpt_completion(prompt: str, openai_api_key: str):
10
- openai.api_key = openai_api_key
11
- response = openai.Completion.create(model="text-davinci-003",
12
- prompt=prompt,
13
- temperature=0,
14
- max_tokens=100)
15
-
16
- return response.choices[0].text.strip()
17
 
 
 
18
 
19
- input_text = gr.components.Textbox(label="Enter your GPT prompt here (User Input)", value='Rewrite and continue this email to let the specific user know the next steps for their lease, "hey user with email [email protected] (last logged in from 127.0.0.1), here\'s the lease agreement for your new property":')
20
- output_text1 = gr.components.Textbox(label="Redacted User Input")
21
- output_text2 = gr.components.Textbox(label="GPT-3 Prompt Completion (on Redacted Input)")
22
 
23
-
24
- def main(oai_api_key, pangea_token, input_text):
 
25
  redacted_text = redact_input(input_text, pangea_token)
26
- completion = gpt_completion(redacted_text, oai_api_key)
27
- return [redacted_text, completion]
28
 
29
- openai_api_key_input = gr.components.Textbox(label="OpenAI API Key (Not stored)", type="password", placeholder="sk-......")
30
- pangea_token_input = gr.components.Textbox(label="Pangea Redact Token (Not stored)", type="password", placeholder="pts_.....")
31
 
32
  iface = gr.Interface(
33
  fn=main,
34
- inputs=[openai_api_key_input, pangea_token_input, input_text],
35
- outputs=[output_text1, output_text2],
36
- title="GPT-3 Input Redaction Playground",
37
- description="<center>Enter your OpenAI key and your Pangea redact token, then put in your prompt and watch the magic happen 🪄. <br/>\
38
- Data redaction is powered by <a href=\"https://pangea.cloud/?utm_source=huggingface&utm_medium=redact-gpt-prompt-demo\">Pangea's APIs</a> in this demo. To learn more about how to get your API keys and tokens to run this, watch this short <a href=\"https://www.youtube.com/watch?v=LNN5s_6G3Cc\" target=\"_blank\">walkthrough demo</a></center>",
39
  allow_flagging="never"
40
  )
41
  iface.launch(
 
1
  import gradio as gr
2
  from pangea.services import Redact
3
+ import os
4
 
5
  def redact_input(input: str, pangea_token: str):
6
  redact = Redact(token=pangea_token)
7
  return redact.redact(text=input).result.redacted_text
8
 
 
 
 
 
 
 
 
 
9
 
10
+ input_text = gr.components.Textbox(label="Enter your data here", value='My credit card number is 4242424242424242 with first and last name Mark Wittner and phone number 240-555-2323 \n City: New York \n State: NY')
11
+ output_text1 = gr.components.Textbox(label="Redacted data")
12
 
 
 
 
13
 
14
+ def main(pangea_token, input_text):
15
+ if pangea_token == "defualt":
16
+ pangea_token = os.environ["PANGEA_REDACT_TOKEN"]
17
  redacted_text = redact_input(input_text, pangea_token)
18
+ return redacted_text
 
19
 
20
+ pangea_token_input = gr.components.Textbox(label="Pangea Redact Token (Optional)", type="password", value="defualt", placeholder="pts_.....")
 
21
 
22
  iface = gr.Interface(
23
  fn=main,
24
+ inputs=[pangea_token_input, input_text],
25
+ outputs=[output_text1],
26
+ title="Data Redaction Playground",
27
+ description="<center>Enter your your Pangea redact token (optional for custom settings), then put in your data and watch the magic happen 🪄. <br/>\
28
+ Data redaction is powered by <a href=\"https://pangea.cloud/?utm_source=huggingface&utm_medium=redact-hash-demo\">Pangea's APIs</a> in this demo. To learn more about how to get your API keys and tokens to run this, watch this short <a href=\"https://www.youtube.com/watch?v=LNN5s_6G3Cc\" target=\"_blank\">walkthrough demo</a></center>",
29
  allow_flagging="never"
30
  )
31
  iface.launch(
requirements.txt CHANGED
@@ -1,2 +1 @@
1
- pangea-sdk
2
- openai
 
1
+ pangea-sdk