From e2d29521f3901ba8ca0c72578e25e8da30e7c09f Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Sat, 16 Nov 2024 11:45:26 -0600 Subject: [PATCH 1/4] added get jobs --- libs/labelbox/src/labelbox/schema/project.py | 76 +++++++++++++++++++ .../annotation_import/test_label_import.py | 13 ++++ .../test_mal_prediction_import.py | 13 ++++ 3 files changed, 102 insertions(+) diff --git a/libs/labelbox/src/labelbox/schema/project.py b/libs/labelbox/src/labelbox/schema/project.py index 2589e6ab1..59f750cf1 100644 --- a/libs/labelbox/src/labelbox/schema/project.py +++ b/libs/labelbox/src/labelbox/schema/project.py @@ -16,6 +16,7 @@ get_args, ) +from labelbox.schema.annotation_import import LabelImport, MALPredictionImport from lbox.exceptions import ( InvalidQueryError, LabelboxError, @@ -710,6 +711,81 @@ def _connect_default_labeling_front_end(self, ontology_as_dict: dict): }, ) + def get_mal_prediction_imports(self) -> PaginatedCollection: + """Returns mal prediction import objects which are used in model-assisted labeling associated with the project. + These are returned with the oldest first, and most recent last. + """ + + id_param = "projectId" + query_str = """ + query getModelAssistedLabelingPredictionImportsPyApi($%s: ID!) { + modelAssistedLabelingPredictionImports(skip: %%d, first: %%d, where: { projectId: $%s }) { %s }} + """ % ( + id_param, + id_param, + query.results_query_part(MALPredictionImport), + ) + + return PaginatedCollection( + self.client, + query_str, + {id_param: self.uid}, + ["modelAssistedLabelingPredictionImports"], + MALPredictionImport, + ) + + def get_label_imports(self) -> PaginatedCollection: + """Returns label import objects associated with the project. + These are returned with the oldest first, and most recent last. + + Returns: + PaginatedCollection. + """ + + id_param = "projectId" + query_str = """ + query getLabelImportsPyApi($%s: ID!) { + labelImports(skip: %%d, first: %%d, where: { projectId: $%s }) { %s }} + """ % ( + id_param, + id_param, + query.results_query_part(LabelImport), + ) + + return PaginatedCollection( + self.client, + query_str, + {id_param: self.uid}, + ["labelImports"], + LabelImport, + ) + + def get_annotation_imports(self) -> PaginatedCollection: + """Returns label import objects associated with the project. + These are returned with the oldest first, and most recent last. + + Returns: + PaginatedCollection. + """ + + id_param = "projectId" + query_str = """ + query getLabelImportsPyApi($%s: ID!) { + labelImports(skip: %%d, first: %%d, where: { projectId: $%s }) { %s }} + """ % ( + id_param, + id_param, + query.results_query_part(LabelImport), + ) + + return PaginatedCollection( + self.client, + query_str, + {id_param: self.uid}, + ["labelImports"], + LabelImport, + ) + def create_batch( self, name: str, diff --git a/libs/labelbox/tests/data/annotation_import/test_label_import.py b/libs/labelbox/tests/data/annotation_import/test_label_import.py index 5576025fd..87741c1b7 100644 --- a/libs/labelbox/tests/data/annotation_import/test_label_import.py +++ b/libs/labelbox/tests/data/annotation_import/test_label_import.py @@ -136,6 +136,19 @@ def test_get(client, module_project, annotation_import_test_helpers): annotation_import_test_helpers.check_running_state(label_import, name, url) +def test_get_import_jobs_from_project(client, configured_project): + name = str(uuid.uuid4()) + url = "https://storage.googleapis.com/labelbox-public-bucket/predictions_test_v2.ndjson" + label_import = LabelImport.create_from_url( + client=client, project_id=configured_project.uid, name=name, url=url + ) + label_import.wait_until_done() + + label_imports = list(configured_project.get_label_imports()) + assert len(label_imports) == 1 + assert label_imports[0].input_file_url == url + + @pytest.mark.slow def test_wait_till_done(client, module_project, predictions): name = str(uuid.uuid4()) diff --git a/libs/labelbox/tests/data/annotation_import/test_mal_prediction_import.py b/libs/labelbox/tests/data/annotation_import/test_mal_prediction_import.py index 3ffd6bfc1..5795ccb5c 100644 --- a/libs/labelbox/tests/data/annotation_import/test_mal_prediction_import.py +++ b/libs/labelbox/tests/data/annotation_import/test_mal_prediction_import.py @@ -65,3 +65,16 @@ def test_create_with_path_arg( annotation_import_test_helpers.assert_file_content( label_import.input_file_url, object_predictions ) + + +def test_get_mal_import_jobs_from_project(client, configured_project): + name = str(uuid.uuid4()) + url = "https://storage.googleapis.com/labelbox-public-bucket/predictions_test_v2.ndjson" + label_import = MALPredictionImport.create( + client=client, id=configured_project.uid, name=name, url=url + ) + label_import.wait_until_done() + + label_imports = list(configured_project.get_mal_prediction_imports()) + assert len(label_imports) == 1 + assert label_imports[0].input_file_url == url From b5d4dae3f166c32a1740a071d5756e5176b4a886 Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Sat, 16 Nov 2024 11:48:52 -0600 Subject: [PATCH 2/4] removed annotation imports --- libs/labelbox/src/labelbox/schema/project.py | 26 -------------------- 1 file changed, 26 deletions(-) diff --git a/libs/labelbox/src/labelbox/schema/project.py b/libs/labelbox/src/labelbox/schema/project.py index 59f750cf1..4022fba7b 100644 --- a/libs/labelbox/src/labelbox/schema/project.py +++ b/libs/labelbox/src/labelbox/schema/project.py @@ -760,32 +760,6 @@ def get_label_imports(self) -> PaginatedCollection: LabelImport, ) - def get_annotation_imports(self) -> PaginatedCollection: - """Returns label import objects associated with the project. - These are returned with the oldest first, and most recent last. - - Returns: - PaginatedCollection. - """ - - id_param = "projectId" - query_str = """ - query getLabelImportsPyApi($%s: ID!) { - labelImports(skip: %%d, first: %%d, where: { projectId: $%s }) { %s }} - """ % ( - id_param, - id_param, - query.results_query_part(LabelImport), - ) - - return PaginatedCollection( - self.client, - query_str, - {id_param: self.uid}, - ["labelImports"], - LabelImport, - ) - def create_batch( self, name: str, From 052fe2027b94f5076066cd2f645fffd4784728eb Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Sat, 16 Nov 2024 11:50:37 -0600 Subject: [PATCH 3/4] typos --- libs/labelbox/src/labelbox/schema/project.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libs/labelbox/src/labelbox/schema/project.py b/libs/labelbox/src/labelbox/schema/project.py index 4022fba7b..1916d3e8c 100644 --- a/libs/labelbox/src/labelbox/schema/project.py +++ b/libs/labelbox/src/labelbox/schema/project.py @@ -713,7 +713,9 @@ def _connect_default_labeling_front_end(self, ontology_as_dict: dict): def get_mal_prediction_imports(self) -> PaginatedCollection: """Returns mal prediction import objects which are used in model-assisted labeling associated with the project. - These are returned with the oldest first, and most recent last. + + Returns: + PaginatedCollection """ id_param = "projectId" @@ -736,10 +738,9 @@ def get_mal_prediction_imports(self) -> PaginatedCollection: def get_label_imports(self) -> PaginatedCollection: """Returns label import objects associated with the project. - These are returned with the oldest first, and most recent last. Returns: - PaginatedCollection. + PaginatedCollection """ id_param = "projectId" From 60c20f98e1196f31e83603d74d1599df613e139a Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Sat, 16 Nov 2024 16:10:56 -0600 Subject: [PATCH 4/4] added delete path since it is small --- .../src/labelbox/schema/annotation_import.py | 14 ++++++++++++++ .../test_mal_prediction_import.py | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/libs/labelbox/src/labelbox/schema/annotation_import.py b/libs/labelbox/src/labelbox/schema/annotation_import.py index 497ac899d..c12d3b250 100644 --- a/libs/labelbox/src/labelbox/schema/annotation_import.py +++ b/libs/labelbox/src/labelbox/schema/annotation_import.py @@ -587,6 +587,20 @@ def parent_id(self) -> str: """ return self.project().uid + def delete(self) -> None: + """ + Deletes a MALPredictionImport job + """ + + query_string = """ + mutation deleteModelAssistedLabelingPredictionImportPyApi($id: ID!) { + deleteModelAssistedLabelingPredictionImport(where: { id: $id }) { + id + } + } + """ + self.client.execute(query_string, {"id": self.uid}) + @classmethod def create_from_file( cls, client: "labelbox.Client", project_id: str, name: str, path: str diff --git a/libs/labelbox/tests/data/annotation_import/test_mal_prediction_import.py b/libs/labelbox/tests/data/annotation_import/test_mal_prediction_import.py index 5795ccb5c..fe1634ba2 100644 --- a/libs/labelbox/tests/data/annotation_import/test_mal_prediction_import.py +++ b/libs/labelbox/tests/data/annotation_import/test_mal_prediction_import.py @@ -78,3 +78,7 @@ def test_get_mal_import_jobs_from_project(client, configured_project): label_imports = list(configured_project.get_mal_prediction_imports()) assert len(label_imports) == 1 assert label_imports[0].input_file_url == url + + label_imports[0].delete() + label_imports = list(configured_project.get_mal_prediction_imports()) + assert len(label_imports) == 0