1- from labelbox .schema .annotation_import import AnnotationImport , MALPredictionImport , MEAPredictionImport
2- from pathlib import Path
31from typing import Dict , Iterable , Union
2+ from pathlib import Path
3+
4+ from labelbox .utils import uuid_to_cuid
5+ from labelbox .pagination import PaginatedCollection
6+ from labelbox .schema .annotation_import import MEAPredictionImport
7+ from labelbox .orm .query import results_query_part
48from labelbox .orm .model import Field , Relationship
59from labelbox .orm .db_object import DbObject
610
@@ -10,6 +14,7 @@ class ModelRun(DbObject):
1014 updated_at = Field .DateTime ("updated_at" )
1115 created_at = Field .DateTime ("created_at" )
1216 created_by_id = Field .String ("created_by_id" , "createdBy" )
17+ model_id = Field .String ("model_id" )
1318
1419 def upsert_labels (self , label_ids ):
1520
@@ -55,3 +60,33 @@ def add_predictions(
5560 else :
5661 raise ValueError (
5762 f'Invalid annotations given of type: { type (annotations )} ' )
63+
64+ def annotation_groups (self ):
65+ query_str = """
66+ query modelRunPyApi($modelRunId: ID!, $from : String, $first: Int){
67+ annotationGroups(where: {modelRunId: {id: $modelRunId}}, after: $from, first: $first)
68+ {nodes{%s},pageInfo{endCursor}}
69+ }
70+ """ % (results_query_part (AnnotationGroup ))
71+ return PaginatedCollection (
72+ self .client , query_str , {'modelRunId' : self .uid },
73+ ['annotationGroups' , 'nodes' ],
74+ lambda client , res : AnnotationGroup (client , self .model_id , res ),
75+ ['annotationGroups' , 'pageInfo' , 'endCursor' ])
76+
77+
78+ class AnnotationGroup (DbObject ):
79+ label_id = Field .String ("label_id" )
80+ model_run_id = Field .String ("model_run_id" )
81+ data_row = Relationship .ToOne ("DataRow" , False , cache = True )
82+
83+ def __init__ (self , client , model_id , field_values ):
84+ field_values ['labelId' ] = uuid_to_cuid (field_values ['labelId' ])
85+ super ().__init__ (client , field_values )
86+ self .model_id = model_id
87+
88+ @property
89+ def url (self ):
90+ app_url = self .client .app_url
91+ endpoint = f"{ app_url } /models/{ self .model_id } /{ self .model_run_id } /AllDatarowsSlice/{ self .uid } ?view=carousel"
92+ return endpoint
0 commit comments