diff --git a/setup.py b/setup.py index 897c7e7..f4cf554 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="CVAT wrapper", - version="0.0.10", + version="0.0.11", author="antwxne", author_email="antoine.desruet@epitech.eu", description="Python wrapper for CVAT API", diff --git a/src/CVAT/Predictions/Foodvisor.py b/src/CVAT/Predictions/Foodvisor.py index c450f1f..e0d3a2d 100644 --- a/src/CVAT/Predictions/Foodvisor.py +++ b/src/CVAT/Predictions/Foodvisor.py @@ -12,7 +12,7 @@ def __init__(self, prediction: list[dict], frame_map: dict, label_map: dict): asset["externalId"] in frame_map ] - def export(self) -> LabeledData: + def export(self, display_response: bool = False) -> LabeledData: shapes: list[dict] = [] tags: list[dict] = [] for asset in self.assets: @@ -44,7 +44,7 @@ def to_shapes(self) -> list[dict]: """ return [annotation.to_json() for annotation in self.annotations] - def to_tags(self) -> list[dict]: + def to_tags(self, display_response: bool = False) -> list[dict]: """ > The function takes a `Question` object as input and returns a list of dictionaries, each of which represents a tag @@ -52,19 +52,21 @@ def to_tags(self) -> list[dict]: Returns: A list of dictionaries. """ - tags = [{ - "frame": self.image.frame_number, - "label_id": self.choice.id, - "group": 0, - "source": "manual", - "attributes": [ - { - "spec_id": self.choice.attributes[0]["id"], - "value": "Je ne sais pas" - } - ] - }] - if True: + tags: list[dict] = [] + if not display_response: + tags.append({ + "frame": self.image.frame_number, + "label_id": self.choice.id, + "group": 0, + "source": "manual", + "attributes": [ + { + "spec_id": self.choice.attributes[0]["id"], + "value": "Je ne sais pas" + } + ] + }) + else: tags.append( { "frame": self.image.frame_number, diff --git a/src/CVAT/Predictions/Interface.py b/src/CVAT/Predictions/Interface.py index 2ed1e7d..43c7a1d 100644 --- a/src/CVAT/Predictions/Interface.py +++ b/src/CVAT/Predictions/Interface.py @@ -23,8 +23,11 @@ def __init__(self, prediction: Union[list[dict], dict], frame_map: dict, label_m raise NotImplementedError @abc.abstractmethod - def export(self) -> LabeledData: + def export(self, display_response: bool = False) -> LabeledData: """ - > This function takes in a `self` object and returns a `LabeledData` object + > This function takes in a boolean value and returns a LabeledData object + + Args: + display_response (bool): If True, the response will be displayed in the output. Defaults to False """ raise NotImplementedError diff --git a/src/CVAT/_put.py b/src/CVAT/_put.py index 2b5c17f..e5cacd7 100644 --- a/src/CVAT/_put.py +++ b/src/CVAT/_put.py @@ -14,11 +14,19 @@ class Put: def __init__(self): raise NotImplementedError - def upload_predictions(self, task: Task, prediction: IPrediction) -> None: - a = prediction.export().to_json() + def upload_predictions(self, task: Task, prediction: IPrediction, display_response: bool = False) -> None: + """ + It takes a task and a prediction, converts the prediction to JSON, and sends it to the server + + Args: + task (Task): Task - the task object that you want to upload the prediction to + prediction (IPrediction): IPrediction - the prediction object that you want to upload + display_response (bool): bool = False. Defaults to False + """ + prediction_json: dict = prediction.export(display_response).to_json() response: Response = self.session.put( url=f'{self.url}/api/tasks/{task.id}/annotations', - json=a + json=prediction_json ) if response.status_code != 200: raise Exception(response.content)