2424 search_annotation_classes
2525)
2626from .project_api import get_project_metadata_bare
27+ from ..common import process_api_response
28+ from ..parameter_decorators import project_metadata
2729
2830logger = logging .getLogger ("superannotate-python-sdk" )
2931
@@ -43,7 +45,10 @@ def _get_project_root_folder_id(project):
4345 )
4446 if not response .ok :
4547 raise SABaseException (response .status_code , response .text )
46- return response .json ()['folder_id' ]
48+
49+ response = process_api_response (response .json ())
50+
51+ return response ['folder_id' ]
4752
4853
4954def search_images (
@@ -94,14 +99,16 @@ def search_images(
9499 )
95100 if response .ok :
96101 # print(response.json())
97- results = response .json ()["data" ]
102+ response = process_api_response (response .json ())
103+ results = response ["data" ]
98104 total_got += len (results )
99105 for r in results :
100106 if return_metadata :
101107 result_list .append (r )
102108 else :
103109 result_list .append (r ["name" ])
104- if response .json ()["count" ] <= total_got :
110+
111+ if response ["count" ] <= total_got :
105112 break
106113 params ["offset" ] = total_got
107114 # print(
@@ -126,7 +133,8 @@ def process_result(x):
126133 return result_list
127134
128135
129- def get_image_metadata (project , image_name ):
136+ @project_metadata
137+ def get_image_metadata (project , image_names ):
130138 """Returns image metadata
131139
132140 :param project: project name or metadata of the project
@@ -137,11 +145,42 @@ def get_image_metadata(project, image_name):
137145 :return: metadata of image
138146 :rtype: dict
139147 """
140- images = search_images (project , image_name , return_metadata = True )
141- for image in images :
142- if image ["name" ] == image_name :
143- return image
144- raise SABaseException (0 , "Image " + image_name + " doesn't exist." )
148+ if isinstance (image_names , str ):
149+ image_names = [image_names ]
150+
151+ json_req = {
152+ 'project_id' : project ['id' ],
153+ 'team_id' : _api .team_id ,
154+ 'names' : image_names
155+ }
156+ response = _api .send_request (
157+ req_type = 'POST' ,
158+ path = '/images/getBulk' ,
159+ json_req = json_req ,
160+ )
161+
162+ metadata = response .json ()
163+ if len (metadata ) == 0 :
164+ raise SABaseException (
165+ 0 ,
166+ f"None of the images in { image_names } exist in the provided project"
167+ )
168+ for item in metadata :
169+ item ['annotation_status' ] = common .annotation_status_int_to_str (
170+ item ['annotation_status' ]
171+ )
172+ item ['prediction_status'
173+ ] = common .prediction_segmentation_status_from_int_to_str (
174+ item ['prediction_status' ]
175+ )
176+ item ['segmentation_status'
177+ ] = common .prediction_segmentation_status_from_int_to_str (
178+ item ['segmentation_status' ]
179+ )
180+
181+ if len (metadata ) == 1 :
182+ return metadata [0 ]
183+ return metadata
145184
146185
147186def set_image_annotation_status (project , image_name , annotation_status ):
@@ -174,7 +213,10 @@ def set_image_annotation_status(project, image_name, annotation_status):
174213 )
175214 if not response .ok :
176215 raise SABaseException (response .status_code , response .text )
177- return response .json ()
216+
217+ response = process_api_response (response .json ())
218+
219+ return response
178220
179221
180222def add_annotation_comment_to_image (
0 commit comments