1313from groundlight_openapi_client .api .labels_api import LabelsApi
1414from groundlight_openapi_client .api .user_api import UserApi
1515from groundlight_openapi_client .exceptions import NotFoundException , UnauthorizedException
16+ from groundlight_openapi_client .model .b_box_geometry_request import BBoxGeometryRequest
1617from groundlight_openapi_client .model .detector_creation_input_request import DetectorCreationInputRequest
1718from groundlight_openapi_client .model .label_value_request import LabelValueRequest
1819from groundlight_openapi_client .model .patched_detector_request import PatchedDetectorRequest
20+ from groundlight_openapi_client .model .roi_request import ROIRequest
1921from model import (
2022 ROI ,
2123 BinaryClassificationResult ,
2628)
2729from urllib3 .exceptions import InsecureRequestWarning
2830
29- from groundlight .binary_labels import Label , convert_display_label_to_internal , convert_internal_label_to_display
31+ from groundlight .binary_labels import Label , convert_internal_label_to_display
3032from groundlight .config import API_TOKEN_MISSING_HELP_MESSAGE , API_TOKEN_VARIABLE_NAME , DISABLE_TLS_VARIABLE_NAME
3133from groundlight .encodings import url_encode_dict
3234from groundlight .images import ByteStreamWrapper , parse_supported_image_types
@@ -1066,16 +1068,17 @@ def _wait_for_result(
10661068 image_query = self ._fixup_image_query (image_query )
10671069 return image_query
10681070
1071+ # pylint: disable=duplicate-code
10691072 def add_label (
1070- self , image_query : Union [ImageQuery , str ], label : Union [Label , str ], rois : Union [List [ROI ], str , None ] = None
1073+ self , image_query : Union [ImageQuery , str ], label : Union [Label , int , str ], rois : Union [List [ROI ], str , None ] = None
10711074 ):
10721075 """
10731076 Provide a new label (annotation) for an image query. This is used to provide ground-truth labels
10741077 for training detectors, or to correct the results of detectors.
10751078
10761079 **Example usage**::
10771080
1078- gl = Groundlight ()
1081+ gl = ExperimentalApi ()
10791082
10801083 # Using an ImageQuery object
10811084 image_query = gl.ask_ml(detector_id, image_data)
@@ -1088,27 +1091,41 @@ def add_label(
10881091 rois = [ROI(x=100, y=100, width=50, height=50)]
10891092 gl.add_label(image_query, "YES", rois=rois)
10901093
1091- :param image_query: Either an ImageQuery object (returned from methods like :meth:`ask_ml`) or an image query ID
1092- string starting with "iq_".
1093- :param label: The label value to assign, typically "YES" or "NO" for binary classification detectors.
1094- For multi-class detectors, use one of the defined class names.
1095- :param rois: Optional list of ROI objects defining regions of interest in the image.
1096- Each ROI specifies a bounding box with x, y coordinates and width, height.
1094+ :param image_query: Either an ImageQuery object (returned from methods like
1095+ `ask_ml`) or an image query ID string starting with "iq_".
1096+
1097+ :param label: The label value to assign, typically "YES" or "NO" for binary
1098+ classification detectors. For multi-class detectors, use one of
1099+ the defined class names.
1100+
1101+ :param rois: Optional list of ROI objects defining regions of interest in the
1102+ image. Each ROI specifies a bounding box with x, y coordinates
1103+ and width, height.
10971104
10981105 :return: None
10991106 """
11001107 if isinstance (rois , str ):
11011108 raise TypeError ("rois must be a list of ROI objects. CLI support is not implemented" )
1109+ if isinstance (label , int ):
1110+ label = str (label )
11021111 if isinstance (image_query , ImageQuery ):
11031112 image_query_id = image_query .id
11041113 else :
11051114 image_query_id = str (image_query )
11061115 # Some old imagequery id's started with "chk_"
1116+ # TODO: handle iqe_ for image_queries returned from edge endpoints
11071117 if not image_query_id .startswith (("chk_" , "iq_" )):
11081118 raise ValueError (f"Invalid image query id { image_query_id } " )
1109- api_label = convert_display_label_to_internal (image_query_id , label )
1110- rois_json = [roi .dict () for roi in rois ] if rois else None
1111- request_params = LabelValueRequest (label = api_label , image_query_id = image_query_id , rois = rois_json )
1119+ geometry_requests = [BBoxGeometryRequest (** roi .geometry .dict ()) for roi in rois ] if rois else None
1120+ roi_requests = (
1121+ [
1122+ ROIRequest (label = roi .label , score = roi .score , geometry = geometry )
1123+ for roi , geometry in zip (rois , geometry_requests )
1124+ ]
1125+ if rois and geometry_requests
1126+ else None
1127+ )
1128+ request_params = LabelValueRequest (label = label , image_query_id = image_query_id , rois = roi_requests )
11121129 self .labels_api .create_label (request_params )
11131130
11141131 def start_inspection (self ) -> str :
0 commit comments