forked from kili-technology/kili-python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset_asset_to_be_labeled_by.py
More file actions
54 lines (40 loc) · 1.51 KB
/
set_asset_to_be_labeled_by.py
File metadata and controls
54 lines (40 loc) · 1.51 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
import click
import yaml
from tqdm import tqdm
from kili.client import Kili
def get(dic, key):
if key not in dic:
return ''
return dic[key]
def get_asset_by_external_id(kili, project_id, external_id):
assets = kili.assets(
project_id=project_id, external_id_contains=[external_id])
assert len(assets) == 1
return assets[0]
@click.command()
@click.option('--api-endpoint', default=None,
help='Endpoint of GraphQL client',
show_default=(
"'KILI_API_ENDPOINT' environment variable or "
"'https://cloud.kili-technology.com/api/label/v2/graphql' if not set"
)
)
def main(api_endpoint):
api_key = input('Enter API KEY: ')
project_id = input('Enter project id: ')
with open('./conf/new_assets.yml', 'r') as f:
configuration = yaml.safe_load(f)
assets = configuration['assets']
kili = Kili(api_key=api_key, api_endpoint=api_endpoint)
project = kili.projects(project_id=project_id)[0]
roles = get(project, 'roles')
for asset in tqdm(assets):
external_id = get(asset, 'externalId')
to_be_labeled_by = [get(user, 'email')
for user in get(asset, 'toBeLabeledBy')]
asset = get_asset_by_external_id(kili, project_id, external_id)
asset_id = get(asset, 'id')
kili.update_properties_in_assets(
asset_ids=[asset_id], to_be_labeled_by_array=[to_be_labeled_by])
if __name__ == '__main__':
main()