|
1 | 1 | import os
|
2 | 2 | from io import BytesIO
|
| 3 | +from typing import Union |
3 | 4 |
|
4 | 5 | from model import Detector, ImageQuery, PaginatedDetectorList, PaginatedImageQueryList
|
5 | 6 | from openapi_client import ApiClient, Configuration
|
6 | 7 | from openapi_client.api.detectors_api import DetectorsApi
|
7 | 8 | from openapi_client.api.image_queries_api import ImageQueriesApi
|
8 | 9 | from openapi_client.model.detector_creation_input import DetectorCreationInput
|
9 | 10 |
|
| 11 | +from groundlight.images import bytesio_from_jpeg_file |
| 12 | + |
10 | 13 | API_TOKEN_WEB_URL = "https://app.positronix.ai/reef/my-account/api-tokens"
|
11 | 14 | API_TOKEN_VARIABLE_NAME = "GROUNDLIGHT_API_TOKEN"
|
12 | 15 |
|
@@ -75,6 +78,16 @@ def list_image_queries(self, page: int = 1, page_size: int = 10) -> PaginatedIma
|
75 | 78 | obj = self.image_queries_api.list_image_queries(page=page, page_size=page_size)
|
76 | 79 | return PaginatedImageQueryList.parse_obj(obj.to_dict())
|
77 | 80 |
|
78 |
| - def submit_image_query(self, detector_id: str, image_bytesio: BytesIO) -> ImageQuery: |
| 81 | + def submit_image_query(self, detector_id: str, image: Union[str, bytes, BytesIO]) -> ImageQuery: |
| 82 | + if isinstance(image, str): |
| 83 | + # Assume it is a filename |
| 84 | + image_bytesio = bytesio_from_jpeg_file(image) |
| 85 | + elif isinstance(image, bytes): |
| 86 | + # Create a BytesIO object |
| 87 | + image_bytesio = BytesIO(image) |
| 88 | + elif isinstance(image, BytesIO): |
| 89 | + # Already in the right format |
| 90 | + image_bytesio = image |
| 91 | + |
79 | 92 | obj = self.image_queries_api.submit_image_query(detector_id=detector_id, body=image_bytesio)
|
80 | 93 | return ImageQuery.parse_obj(obj.to_dict())
|
0 commit comments