File size: 1,128 Bytes
53d8966
7edad11
 
 
fa07efb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8a84b3b
 
fa07efb
 
cf44933
8a84b3b
1762fcc
53d8966
 
fa07efb
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
import gradio as gr
import requests


def extract_pii(text):
    res = requests.post(
        "https://6b044.cognitiveservices.azure.com/language/:analyze-text?api-version=2022-05-01",
        headers={
            "Ocp-Apim-Subscription-Key": "941b608ce2634805b169eca63f51b856",
            "Content-Type": "application/json",
        },
        json={
            "kind": "PiiEntityRecognition",
            "parameters": {
                "modelVersion": "latest",
            },
            "analysisInput":{
                "documents":[
                    {
                        "id":"1",
                        "language": "en",
                        "text": text,
                    },
                ],
            },
        },
    )
    pii_entities = res.json()["results"]["documents"][0]["entities"]
    return list(map(lambda row: [row["text"], row["category"], row["confidenceScore"]], pii_entities))

demo = gr.Interface(extract_pii, inputs=gr.Textbox(label="Text for PII extraction"), outputs=gr.DataFrame(headers=["Text", "Category", "Confidence Score"]))

if __name__ == "__main__":
    demo.launch()