Spaces:
Sleeping
Sleeping
initial commit
Browse files- app.py +46 -0
- favicon-32x32.png +0 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from pangea.services import Redact
|
| 3 |
+
import openai
|
| 4 |
+
|
| 5 |
+
def greet(name):
|
| 6 |
+
return "Hello " + name + "!!"
|
| 7 |
+
|
| 8 |
+
def redact_input(input: str, pangea_token: str):
|
| 9 |
+
redact = Redact(token=pangea_token)
|
| 10 |
+
return redact.redact(text=input).result.redacted_text
|
| 11 |
+
|
| 12 |
+
def gpt_completion(prompt: str, openai_api_key: str):
|
| 13 |
+
openai.api_key = openai_api_key
|
| 14 |
+
response = openai.Completion.create(model="text-davinci-003",
|
| 15 |
+
prompt=prompt,
|
| 16 |
+
temperature=0,
|
| 17 |
+
max_tokens=100)
|
| 18 |
+
|
| 19 |
+
return response.choices[0].text.strip()
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
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 dummyuser@email.com (last logged in from 127.0.0.1), here\'s the lease agreement for your new property":')
|
| 23 |
+
output_text1 = gr.components.Textbox(label="Redacted User Input")
|
| 24 |
+
output_text2 = gr.components.Textbox(label="GPT-3 Prompt Completion (on Redacted Input)")
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def main(oai_api_key, pangea_token, input_text):
|
| 28 |
+
redacted_text = redact_input(input_text, pangea_token)
|
| 29 |
+
completion = gpt_completion(redacted_text, oai_api_key)
|
| 30 |
+
return [redacted_text, completion]
|
| 31 |
+
|
| 32 |
+
openai_api_key_input = gr.components.Textbox(label="OpenAI API Key (Not stored)", type="password", placeholder="sk-......")
|
| 33 |
+
pangea_token_input = gr.components.Textbox(label="Pangea Redact Token (Not stored)", type="password", placeholder="pts_.....")
|
| 34 |
+
|
| 35 |
+
iface = gr.Interface(
|
| 36 |
+
fn=main,
|
| 37 |
+
inputs=[openai_api_key_input, pangea_token_input, input_text],
|
| 38 |
+
outputs=[output_text1, output_text2],
|
| 39 |
+
title="GPT-3 Input Redaction Playground",
|
| 40 |
+
description="<center>Enter your OpenAI key and your Pangea redact token, then put in your prompt and watch the magic happen 🪄. <br/>\
|
| 41 |
+
To learn about getting the write API keys and tokens, watch this short <a href=\"https://www.youtube.com/watch?v=LNN5s_6G3Cc\" target=\"_blank\">walkthrough demo</a></center>",
|
| 42 |
+
allow_flagging="never"
|
| 43 |
+
)
|
| 44 |
+
iface.launch(
|
| 45 |
+
favicon_path="./favicon-32x32.png"
|
| 46 |
+
)
|
favicon-32x32.png
ADDED
|
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pangea-sdk
|
| 2 |
+
openai
|