-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow submiting images alongside notes in the sdk #232
Changes from 13 commits
a366490
d993287
4d335ff
6a711d6
0a1fa17
1d49190
2049f07
3241983
46f1dc2
475f483
861d73d
f91b0f0
e9a8040
b968dc0
607f5b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
import json | ||
from typing import Any, Dict, List, Tuple, Union | ||
|
||
import requests | ||
from groundlight_openapi_client.api.actions_api import ActionsApi | ||
from groundlight_openapi_client.api.detector_groups_api import DetectorGroupsApi | ||
from groundlight_openapi_client.api.image_queries_api import ImageQueriesApi | ||
|
@@ -19,13 +20,13 @@ | |
from groundlight_openapi_client.model.condition_request import ConditionRequest | ||
from groundlight_openapi_client.model.detector_group_request import DetectorGroupRequest | ||
from groundlight_openapi_client.model.label_value_request import LabelValueRequest | ||
from groundlight_openapi_client.model.note_request import NoteRequest | ||
from groundlight_openapi_client.model.roi_request import ROIRequest | ||
from groundlight_openapi_client.model.rule_request import RuleRequest | ||
from groundlight_openapi_client.model.verb_enum import VerbEnum | ||
from model import ROI, BBoxGeometry, Detector, DetectorGroup, ImageQuery, PaginatedRuleList, Rule | ||
|
||
from groundlight.binary_labels import Label, convert_display_label_to_internal | ||
from groundlight.images import parse_supported_image_types | ||
|
||
from .client import Groundlight | ||
|
||
|
@@ -180,16 +181,26 @@ def get_notes(self, detector: Union[str, Detector]) -> Dict[str, Any]: | |
det_id = detector.id if isinstance(detector, Detector) else detector | ||
return self.notes_api.get_notes(det_id) | ||
|
||
def create_note(self, detector: Union[str, Detector], note: Union[str, NoteRequest]) -> None: | ||
def create_note(self, detector: Union[str, Detector], note: str, image: Union[str, None] = None) -> None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I though There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nailed it, we still support python before 3.10 |
||
""" | ||
Adds a note to a given detector | ||
|
||
:param detector: the detector to add the note to | ||
:param note: the text content of the note | ||
:param image: a path to an image to attach to the note | ||
""" | ||
det_id = detector.id if isinstance(detector, Detector) else detector | ||
if isinstance(note, str): | ||
note = NoteRequest(content=note) | ||
self.notes_api.create_note(det_id, note) | ||
if image is not None: | ||
img_bytes = parse_supported_image_types(image) | ||
# TODO: The openapi generator doesn't handle file submissions well at the moment, so we manually implement this | ||
# kwargs = {"image": img_bytes} | ||
# self.notes_api.create_note(det_id, note, **kwargs) | ||
Comment on lines
+202
to
+204
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will we ever resolve this TODO? Or is it a permanent issue? If permanent I'm not sure you need to include how we would have solved it if the generator worked. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I very much would like to resolve the issue, but it really just doesn't make sense to sink more time right now. This may be resolved in the openapi-generator project. It shouldn't affect us until we decide we want to start porting the SDK into other languages (so not very soon) |
||
url = f"{self.endpoint}/v1/notes" | ||
files = {"image": ("image.jpg", img_bytes, "image/jpeg")} if image is not None else None | ||
data = {"content": note} | ||
params = {"detector_id": det_id} | ||
headers = {"x-api-token": self.configuration.api_key["ApiToken"]} | ||
requests.post(url, headers=headers, data=data, files=files, params=params, timeout=60) # type: ignore | ||
|
||
def create_detector_group(self, name: str) -> DetectorGroup: | ||
""" | ||
|
@@ -234,18 +245,22 @@ def create_roi(self, label: str, top_left: Tuple[float, float], bottom_right: Tu | |
), | ||
) | ||
|
||
# pylint: disable=duplicate-code | ||
def add_label( | ||
self, image_query: Union[ImageQuery, str], label: Union[Label, str], rois: Union[List[ROI], str, None] = None | ||
): | ||
""" | ||
Experimental version of add_label. | ||
Add a new label to an image query. This answers the detector's question. | ||
Experimental version of add_label. Add a new label to an image query. | ||
This answers the detector's question. | ||
|
||
:param image_query: Either an ImageQuery object (returned from `submit_image_query`) | ||
or an image_query id as a string. | ||
:param image_query: Either an ImageQuery object (returned from | ||
`submit_image_query`) or an image_query id as a | ||
string. | ||
|
||
:param label: The string "YES" or the string "NO" in answer to the query. | ||
:param rois: An option list of regions of interest (ROIs) to associate with the label. (This feature experimental) | ||
:param label: The string "YES" or the string "NO" in answer to the | ||
query. | ||
:param rois: An option list of regions of interest (ROIs) to associate | ||
with the label. (This feature experimental) | ||
|
||
:return: None | ||
""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding is that we encourage users to use
ask_*
methods instead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point. Does 'ask_ml or similar method' sound better? ask_* feels a little cheeky