Skip to content

Commit

Permalink
Automatically reformatting code
Browse files Browse the repository at this point in the history
  • Loading branch information
Auto-format Bot committed Oct 9, 2023
1 parent 98307c1 commit 2b3d07e
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/groundlight/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,16 @@
from io import BufferedReader, BytesIO
from typing import Optional, Union

from model import (Detector, ImageQuery, PaginatedDetectorList,
PaginatedImageQueryList)
from model import Detector, ImageQuery, PaginatedDetectorList, PaginatedImageQueryList
from openapi_client import Configuration
from openapi_client.api.detectors_api import DetectorsApi
from openapi_client.api.image_queries_api import ImageQueriesApi
from openapi_client.model.detector_creation_input import DetectorCreationInput

from groundlight.binary_labels import (Label,
convert_display_label_to_internal,
convert_internal_label_to_display)
from groundlight.binary_labels import Label, convert_display_label_to_internal, convert_internal_label_to_display
from groundlight.config import API_TOKEN_VARIABLE_NAME, API_TOKEN_WEB_URL
from groundlight.images import ByteStreamWrapper, parse_supported_image_types
from groundlight.internalapi import (GroundlightApiClient, NotFoundError,
iq_is_confident, sanitize_endpoint_url)
from groundlight.internalapi import GroundlightApiClient, NotFoundError, iq_is_confident, sanitize_endpoint_url
from groundlight.optional_imports import Image, np

logger = logging.getLogger("groundlight.sdk")
Expand Down Expand Up @@ -75,7 +71,7 @@ def __init__(self, endpoint: Optional[str] = None, api_token: Optional[str] = No
self.detectors_api = DetectorsApi(self.api_client)
self.image_queries_api = ImageQueriesApi(self.api_client)

def _fixup_image_query(self, iq: ImageQuery, want_async:bool=False) -> ImageQuery: # pylint: disable=no-self-use
def _fixup_image_query(self, iq: ImageQuery, want_async: bool = False) -> ImageQuery: # pylint: disable=no-self-use
"""
Post process an image query prior to returning it to the user.
:param iq: The image query to fix up.
Expand All @@ -84,8 +80,8 @@ def _fixup_image_query(self, iq: ImageQuery, want_async:bool=False) -> ImageQuer
# Note: This might go away once we clean up the mapping logic server-side.
iq.result.label = convert_internal_label_to_display(iq, iq.result.label)
if want_async:
# If want_async is True, the result returned to the user should be None because the client intentionally
# wants to query for the result later. Any result returned by the server is NOT representative of the
# If want_async is True, the result returned to the user should be None because the client intentionally
# wants to query for the result later. Any result returned by the server is NOT representative of the
# query's actual result.
iq.result = None
return iq
Expand Down Expand Up @@ -224,13 +220,15 @@ def submit_image_query( # noqa: PLR0913 # pylint: disable=too-many-arguments

if human_review is not None:
params["human_review"] = human_review

if want_async is True:
# If want_async is True, we don't want to wait for a result. As a result using both wait and want_async makes
# no sense.
if wait is not None:
raise ValueError("wait must be None if want_async is True as the two are incompatible. Please set wait"
" to None to use want_async.")
raise ValueError(
"wait must be None if want_async is True as the two are incompatible. Please set wait"
" to None to use want_async."
)
params["want_async"] = want_async

# If no inspection_id is provided, we submit the image query using image_queries_api (autogenerated via OpenAPI)
Expand All @@ -247,7 +245,7 @@ def submit_image_query( # noqa: PLR0913 # pylint: disable=too-many-arguments
if wait:
threshold = self.get_detector(detector).confidence_threshold
image_query = self.wait_for_confident_result(image_query, confidence_threshold=threshold, timeout_sec=wait)

return self._fixup_image_query(image_query, want_async=want_async)

def wait_for_confident_result(
Expand Down

0 comments on commit 2b3d07e

Please sign in to comment.