|
30 | 30 | from groundlight_openapi_client.model.payload_template_request import PayloadTemplateRequest
|
31 | 31 | from groundlight_openapi_client.model.rule_request import RuleRequest
|
32 | 32 | from groundlight_openapi_client.model.status_enum import StatusEnum
|
| 33 | +from groundlight_openapi_client.model.text_mode_configuration import TextModeConfiguration |
33 | 34 | from groundlight_openapi_client.model.webhook_action_request import WebhookActionRequest
|
34 | 35 | from model import (
|
35 | 36 | ROI,
|
@@ -1053,6 +1054,60 @@ def create_bounding_box_detector( # noqa: PLR0913 # pylint: disable=too-many-ar
|
1053 | 1054 | obj = self.detectors_api.create_detector(detector_creation_input, _request_timeout=DEFAULT_REQUEST_TIMEOUT)
|
1054 | 1055 | return Detector.parse_obj(obj.to_dict())
|
1055 | 1056 |
|
| 1057 | + def create_text_recognition_detector( |
| 1058 | + self, |
| 1059 | + name: str, |
| 1060 | + query: str, |
| 1061 | + *, |
| 1062 | + group_name: Optional[str] = None, |
| 1063 | + confidence_threshold: Optional[float] = None, |
| 1064 | + patience_time: Optional[float] = None, |
| 1065 | + pipeline_config: Optional[str] = None, |
| 1066 | + metadata: Union[dict, str, None] = None, |
| 1067 | + ) -> Detector: |
| 1068 | + """ |
| 1069 | + Creates a text recognition detector that can read specified spans of text from images. |
| 1070 | +
|
| 1071 | + **Example usage**:: |
| 1072 | +
|
| 1073 | + gl = ExperimentalApi() |
| 1074 | +
|
| 1075 | + # Create a text recognition detector |
| 1076 | + detector = gl.create_text_recognition_detector( |
| 1077 | + name="date_and_time_detector", |
| 1078 | + query="Read the date and time from the bottom left corner of the image.", |
| 1079 | + ) |
| 1080 | +
|
| 1081 | + :param name: A short, descriptive name for the detector. |
| 1082 | + :param query: A question about the object to detect in the image. |
| 1083 | + :param group_name: Optional name of a group to organize related detectors together. |
| 1084 | + :param confidence_threshold: A value that sets the minimum confidence level required for the ML model's |
| 1085 | + predictions. If confidence is below this threshold, the query may be sent for human review. |
| 1086 | + :param patience_time: The maximum time in seconds that Groundlight will attempt to generate a |
| 1087 | + confident prediction before falling back to human review. Defaults to 30 seconds. |
| 1088 | + :param pipeline_config: Advanced usage only. Configuration string needed to instantiate a specific |
| 1089 | + prediction pipeline for this detector. |
| 1090 | + :param metadata: A dictionary or JSON string containing custom key/value pairs to associate with |
| 1091 | +
|
| 1092 | + :return: The created Detector object |
| 1093 | + """ |
| 1094 | + |
| 1095 | + detector_creation_input = self._prep_create_detector( |
| 1096 | + name=name, |
| 1097 | + query=query, |
| 1098 | + group_name=group_name, |
| 1099 | + confidence_threshold=confidence_threshold, |
| 1100 | + patience_time=patience_time, |
| 1101 | + pipeline_config=pipeline_config, |
| 1102 | + metadata=metadata, |
| 1103 | + ) |
| 1104 | + detector_creation_input.mode = ModeEnum.TEXT |
| 1105 | + mode_config = TextModeConfiguration() |
| 1106 | + |
| 1107 | + detector_creation_input.mode_configuration = mode_config |
| 1108 | + obj = self.detectors_api.create_detector(detector_creation_input, _request_timeout=DEFAULT_REQUEST_TIMEOUT) |
| 1109 | + return Detector.parse_obj(obj.to_dict()) |
| 1110 | + |
1056 | 1111 | def _download_mlbinary_url(self, detector: Union[str, Detector]) -> EdgeModelInfo:
|
1057 | 1112 | """
|
1058 | 1113 | Gets a temporary presigned URL to download the model binaries for the given detector, along
|
|
0 commit comments