1
1
from typing import Dict , Iterable , Union
2
2
from pathlib import Path
3
3
import os
4
+ import time
4
5
5
6
from labelbox .pagination import PaginatedCollection
6
7
from labelbox .schema .annotation_import import MEAPredictionImport
@@ -16,6 +17,38 @@ class ModelRun(DbObject):
16
17
created_by_id = Field .String ("created_by_id" , "createdBy" )
17
18
model_id = Field .String ("model_id" )
18
19
20
+ def upsert_labels (self , label_ids , timeout_seconds = 600 ):
21
+ """ Calls GraphQL API to start the MEA labels registration process
22
+ Args:
23
+ label_ids (list): label ids to insert
24
+ timeout_seconds (float): Max waiting time, in seconds.
25
+ Returns:
26
+ ID of newly generated async task
27
+ """
28
+
29
+ sleep_time = 5
30
+
31
+ mutation_name = 'createMEAModelRunLabelRegistrationTask'
32
+ query_str = """mutation createMEAModelRunLabelRegistrationTaskByApi($modelRunId: ID!, $labelIds : [ID!]!) {
33
+ %s(where : { id : $modelRunId}, data : {labelIds: $labelIds})}
34
+ """ (mutation_name )
35
+
36
+ while True :
37
+ res = self .client .execute (query_str , {
38
+ 'modelRunId' : self .uid ,
39
+ 'labelIds' : label_ids
40
+ })
41
+
42
+ res = res [mutation_name ]
43
+ if res :
44
+ return res
45
+
46
+ timeout_seconds -= sleep_time
47
+ if timeout_seconds <= 0 :
48
+ return None
49
+
50
+ time .sleep (sleep_time )
51
+
19
52
def upsert_labels (self , label_ids ):
20
53
21
54
if len (label_ids ) < 1 :
0 commit comments