Repository navigation
Expand file tree
/
Copy pathdeidentify_string.py
More file actions
94 lines (78 loc) · 3.02 KB
/
Copy pathdeidentify_string.py
File metadata and controls
94 lines (78 loc) · 3.02 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from skyflow.error import SkyflowError
from skyflow import Env, Skyflow, LogLevel
from skyflow.vault.detect import DeidentifyStringRequest, DetectConfiguration, Detect, Entity
from skyflow.utils.enums import EntityType, DeidentificationType
def perform_deidentify_string():
try:
vault_config = {
'vault_id': '<YOUR_VAULT_ID>',
'cluster_id': '<YOUR_CLUSTER_ID>',
'env': Env.PROD,
'credentials': {'path': '<PATH_TO_YOUR_CREDENTIALS_JSON>'},
}
skyflow_client = (
Skyflow.builder()
.add_vault_config(vault_config)
.set_log_level(LogLevel.ERROR)
.build()
)
request = DeidentifyStringRequest(
text='My name is John Doe, and my email is johndoe@acme.com.',
configuration_id='<CONFIGURATION_ID>',
)
response = skyflow_client.detect().deidentify_string(request)
print(response.processed_text)
for entity in response.entities:
print(entity.entity_type, entity.token, entity.entity_scores)
except SkyflowError as error:
print('Skyflow Specific Error: ', {
'code': error.http_code,
'message': error.message,
'details': error.details,
'request_id': error.request_id,
})
def perform_deidentify_string_inline():
try:
vault_config = {
'vault_id': '<YOUR_VAULT_ID>',
'cluster_id': '<YOUR_CLUSTER_ID>',
'env': Env.PROD,
'credentials': {'path': '<PATH_TO_YOUR_CREDENTIALS_JSON>'},
}
skyflow_client = (
Skyflow.builder()
.add_vault_config(vault_config)
.set_log_level(LogLevel.ERROR)
.build()
)
request = DeidentifyStringRequest(
text='My name is John Doe, and my email is johndoe@acme.com.',
configuration=DetectConfiguration(
detect=Detect(
entities=[
Entity(
entity_type=EntityType.NAME,
deidentification_type=DeidentificationType.VAULT_TOKEN,
destination='<TOKEN_GROUP_NAME>',
),
Entity(
entity_type=EntityType.ALL,
deidentification_type=DeidentificationType.ENTITY_UNIQUE_COUNTER,
),
],
),
),
)
response = skyflow_client.detect().deidentify_string(request)
print(response.processed_text)
for entity in response.entities:
print(entity.entity_type, entity.token, entity.entity_scores)
except SkyflowError as error:
print('Skyflow Specific Error: ', {
'code': error.http_code,
'message': error.message,
'details': error.details,
'request_id': error.request_id,
})
if __name__ == '__main__':
perform_deidentify_string()