1+ import os .path
2+ from pprint import pprint
3+ import time
4+
5+ from azure .cognitiveservices .vision .contentmoderator import ContentModeratorClient
6+ from azure .cognitiveservices .vision .contentmoderator .models import (
7+ Screen
8+ )
9+ from msrest .authentication import CognitiveServicesCredentials
10+
11+ SUBSCRIPTION_KEY_ENV_NAME = "CONTENTMODERATOR_SUBSCRIPTION_KEY"
12+ CONTENTMODERATOR_LOCATION = os .environ .get ("CONTENTMODERATOR_LOCATION" , "westcentralus" )
13+
14+ # The number of minutes to delay after updating the search index before
15+ # performing image match operations against the list.
16+ LATENCY_DELAY = 0.5
17+
18+ TEXT = """
19+ Is this a grabage email [email protected] , phone: 6657789887, IP: 255.255.255.255, 1 Microsoft Way, Redmond, WA 98052. 20+ Crap is the profanity here. Is this information PII? phone 3144444444
21+ """
22+
23+ def text_moderation (subscription_key ):
24+ """TextModeration.
25+
26+ This will moderate a given long text.
27+ """
28+
29+ client = ContentModeratorClient (
30+ CONTENTMODERATOR_LOCATION + '.api.cognitive.microsoft.com' ,
31+ CognitiveServicesCredentials (subscription_key )
32+ )
33+
34+ # Screen the input text: check for profanity,
35+ # do autocorrect text, and check for personally identifying
36+ # information (PII)
37+ screen = client .text_moderation .screen_text (
38+ "eng" ,
39+ "text/plain" ,
40+ TEXT ,
41+ autocorrect = True ,
42+ pii = True
43+ )
44+ assert isinstance (screen , Screen )
45+ pprint (screen .as_dict ())
46+
47+ if __name__ == "__main__" :
48+ import sys , os .path
49+ sys .path .append (os .path .abspath (os .path .join (__file__ , ".." , ".." )))
50+ from tools import execute_samples
51+ execute_samples (globals (), SUBSCRIPTION_KEY_ENV_NAME )
0 commit comments