File size: 1,915 Bytes
492a45e
 
1110ee8
492a45e
 
 
 
 
 
0531f26
1110ee8
492a45e
 
1110ee8
 
 
492a45e
1110ee8
492a45e
1110ee8
492a45e
 
 
1110ee8
 
 
5ecf44d
 
 
 
 
 
 
9957a3a
 
5ecf44d
492a45e
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import gradio as gr
from pangea.services import Redact
import os

def redact_input(input: str, pangea_token: str):
    redact = Redact(token=pangea_token)
    return redact.redact(text=input).result.redacted_text


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 \n Zip Code: 10036')
output_text1 = gr.components.Textbox(label="Redacted data")


def main(pangea_token, input_text):
    if pangea_token == "defualt":
        pangea_token = os.environ["PANGEA_REDACT_TOKEN"]
    redacted_text = redact_input(input_text, pangea_token)
    return redacted_text

pangea_token_input = gr.components.Textbox(label="Pangea Redact Token (Optional)", type="password", value="defualt", placeholder="pts_.....")

iface = gr.Interface(
    fn=main,
    inputs=[pangea_token_input, input_text],
    outputs=[output_text1],
    title="Data Redaction Playground",
    description="Enter your your Pangea redact token (optional for custom settings), then put in your data and watch the magic happen 🪄.\n\n"
                "Data redaction is powered by [Pangea's APIs](https://pangea.cloud/?utm_source=huggingface&utm_medium=redact-hash-demo) in this demo. "
                "To learn more about how to get your API keys and tokens to run this, watch this short [walkthrough demo](https://www.youtube.com/watch?v=LNN5s_6G3Cc).\n\n"
                "All of this in 3 lines of code:\n"
                "```python\n"
                "from pangea.services import Redact\n"
                "redact = Redact(\"token=<PANGEA_REDACT_TOKEN>\")\n"
                "def clean_data(data):\n"
                "    return redact.redact(text=data).result.redacted_text\n"
                "```",
    allow_flagging="never"
)
iface.launch(
    favicon_path="./favicon-32x32.png"
)