-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Migrate code from googleapis/python-datalabeling #8456
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
Merged
Merged
Changes from 62 commits
Commits
Show all changes
68 commits
Select commit
Hold shift + click to select a range
7858a28
chore: move samples from python-docs-sample to here (#29)
arithmetic1728 cee3077
feat!: migrate to use microgen (#34)
arithmetic1728 71ca67a
samples: updated requierement.txt and enabled list sample test (#48)
munkhuushmgl 1e0adb9
chore: added helpful instruction comment on lable_image sample (#52)
munkhuushmgl 5c99847
feat: add common resource helper paths; expose client transport (#49)
yoshi-automation 213a2e3
chore: currently datalabeling is limited to due to covid 19 (#61)
munkhuushmgl 3f8a868
chore: update templates (#63)
yoshi-automation abebafd
chore: Updating resources and configuration for presubmits and test e…
yoshi-automation 686d515
chore: disabling datalabeling tests due to service limited exception …
munkhuushmgl cc4de63
chore: migrate to owl bot (#96)
parthea f43b1fb
chore(deps): update dependency pytest to v6.2.4 (#97)
renovate-bot 93288af
chore: new owl bot post processor docker image (#103)
gcf-owl-bot[bot] c2e3910
chore(deps): update dependency google-cloud-datalabeling to v1.1.0 (#…
renovate-bot 3e88a9b
chore(deps): update dependency backoff to v1.11.0 (#118)
renovate-bot e7a0dee
chore(deps): update dependency google-cloud-datalabeling to v1.2.0 (#…
renovate-bot 9047b77
chore(deps): update dependency backoff to v1.11.1 (#120)
renovate-bot 49f141a
feat: add Samples section to CONTRIBUTING.rst (#124)
gcf-owl-bot[bot] 8791e61
chore(deps): update dependency google-cloud-datalabeling to v1.2.1 (#…
renovate-bot 3b96719
chore(deps): update dependency google-cloud-datalabeling to v1.2.2 (#…
renovate-bot 20bf518
chore: fix INSTALL_LIBRARY_FROM_SOURCE in noxfile.py (#134)
gcf-owl-bot[bot] d770fa9
chore: drop mention of Python 2.7 from templates (#136)
gcf-owl-bot[bot] 9bebe8c
chore(deps): update dependency pytest to v6.2.5 (#141)
renovate-bot 0aee688
chore: blacken samples noxfile template (#146)
gcf-owl-bot[bot] f99a215
chore: fail samples nox session if python version is missing (#153)
gcf-owl-bot[bot] 7df8fc6
chore(python): Add kokoro configs for python 3.10 samples testing (#158)
gcf-owl-bot[bot] 5191da9
chore(deps): update dependency google-cloud-datalabeling to v1.3.0 (#…
renovate-bot c2fc455
chore(deps): update dependency google-cloud-datalabeling to v1.4.0 (#…
renovate-bot d6620b8
chore(samples): Add check for tests in directory (#181)
gcf-owl-bot[bot] 9a57f84
chore(python): Noxfile recognizes that tests can live in a folder (#185)
gcf-owl-bot[bot] d55abe6
chore(deps): update dependency pytest to v7 (#193)
renovate-bot ed22fe2
chore(deps): update dependency pytest to v7.0.1 (#195)
renovate-bot a01df31
chore(deps): update dependency google-cloud-datalabeling to v1.5.0 (#…
renovate-bot 7133c23
chore: use gapic-generator-python 0.63.2 (#194)
gcf-owl-bot[bot] a62b743
chore: use gapic-generator-python 0.63.4 (#197)
gcf-owl-bot[bot] 5c43f56
chore: update copyright year to 2022 (#198)
gcf-owl-bot[bot] 9093bf9
chore: Adding support for pytest-xdist and pytest-parallel (#207)
gcf-owl-bot[bot] da7ea9d
chore(deps): update dependency google-cloud-datalabeling to v1.5.1 (#…
renovate-bot fcbaeb9
chore(deps): update dependency pytest to v7.1.0 (#212)
renovate-bot 15caff7
chore(deps): update dependency pytest to v7.1.1 (#213)
renovate-bot a64f2a6
chore(python): use black==22.3.0 (#218)
gcf-owl-bot[bot] f936c44
chore: use gapic-generator-python 0.65.1 (#228)
gcf-owl-bot[bot] 44376bc
chore(python): add nox session to sort python imports (#229)
gcf-owl-bot[bot] 0adf632
chore(deps): update dependency pytest to v7.1.2 (#232)
renovate-bot ea1ce9b
chore(deps): update dependency backoff to v2 (#233)
renovate-bot f4d289d
chore(deps): update dependency backoff to v2.0.1 (#235)
renovate-bot ba5bfe3
fix: require python 3.7+ (#251)
gcf-owl-bot[bot] 70d6906
chore(deps): update all dependencies (#245)
renovate-bot a589421
chore(deps): update all dependencies (#257)
renovate-bot 0ab4e21
chore(deps): update dependency google-cloud-datalabeling to v1.6.1 (#…
renovate-bot 4a7715e
chore(deps): update dependency pytest to v7.1.3 (#272)
renovate-bot 8d10ac4
chore: Bump gapic-generator-python version to 1.3.0 (#273)
gcf-owl-bot[bot] 304ffc2
chore: detect samples tests in nested directories (#276)
gcf-owl-bot[bot] 714ce01
chore(deps): update dependency google-cloud-datalabeling to v1.6.2 (#…
renovate-bot b57e518
chore(deps): update dependency backoff to v2.2.1 (#281)
renovate-bot cbc4eb4
chore(deps): update dependency google-cloud-datalabeling to v1.6.3 (#…
renovate-bot ab0e3ba
chore(deps): update dependency pytest to v7.2.0 (#285)
renovate-bot ee4282f
Updated copyright years to 2022
ivanmkc b686d2f
Removed generated samples
ivanmkc 60066eb
Fixed removed files and master-main
ivanmkc e86677c
Merge branch 'main' into python-datalabeling-migration
ivanmkc 0a96c25
Merge branch 'main' into python-datalabeling-migration
ivanmkc d7a9b2d
Updated blunderbuss file
ivanmkc 0833c3e
Update .github/blunderbuss.yml
dandhlee 2daf5ce
Merge branch 'main' into python-datalabeling-migration
ivanmkc ab01032
Added ivanmkc as reviewer
ivanmkc ddd312e
Added to CODEOWNERS
ivanmkc 5dd6664
Merge branch 'main' into python-datalabeling-migration
dandhlee b9844f5
Merge branch 'main' into python-datalabeling-migration
dandhlee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/AUTHORING_GUIDE.md |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/CONTRIBUTING.md |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| .. This file is automatically generated. Do not edit this file directly. | ||
|
|
||
| Google Cloud Data Labeling Service Python Samples | ||
| =============================================================================== | ||
|
|
||
| .. image:: https://gstatic.com/cloudssh/images/open-btn.png | ||
| :target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=datalabeling/README.rst | ||
|
|
||
|
|
||
| This directory contains samples for Google Cloud Data Labeling Service. `Google Cloud Data Labeling Service`_ allows developers to request having human labelers label a collection of data that you plan to use to train a custom machine learning model. | ||
|
|
||
|
|
||
|
|
||
|
|
||
| .. _Google Cloud Data Labeling Service: https://cloud.google.com/data-labeling/docs/ | ||
|
|
||
| Setup | ||
| ------------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| Authentication | ||
| ++++++++++++++ | ||
|
|
||
| This sample requires you to have authentication setup. Refer to the | ||
| `Authentication Getting Started Guide`_ for instructions on setting up | ||
| credentials for applications. | ||
|
|
||
| .. _Authentication Getting Started Guide: | ||
| https://cloud.google.com/docs/authentication/getting-started | ||
|
|
||
| Install Dependencies | ||
| ++++++++++++++++++++ | ||
|
|
||
| #. Clone python-docs-samples and change directory to the sample directory you want to use. | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| $ git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git | ||
|
|
||
| #. Install `pip`_ and `virtualenv`_ if you do not already have them. You may want to refer to the `Python Development Environment Setup Guide`_ for Google Cloud Platform for instructions. | ||
|
|
||
| .. _Python Development Environment Setup Guide: | ||
| https://cloud.google.com/python/setup | ||
|
|
||
| #. Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+. | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| $ virtualenv env | ||
| $ source env/bin/activate | ||
|
|
||
| #. Install the dependencies needed to run the samples. | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| $ pip install -r requirements.txt | ||
|
|
||
| .. _pip: https://pip.pypa.io/ | ||
| .. _virtualenv: https://virtualenv.pypa.io/ | ||
|
|
||
|
|
||
|
|
||
| The client library | ||
| ------------------------------------------------------------------------------- | ||
|
|
||
| This sample uses the `Google Cloud Client Library for Python`_. | ||
| You can read the documentation for more details on API usage and use GitHub | ||
| to `browse the source`_ and `report issues`_. | ||
|
|
||
| .. _Google Cloud Client Library for Python: | ||
| https://googlecloudplatform.github.io/google-cloud-python/ | ||
| .. _browse the source: | ||
| https://github.com/GoogleCloudPlatform/google-cloud-python | ||
| .. _report issues: | ||
| https://github.com/GoogleCloudPlatform/google-cloud-python/issues | ||
|
|
||
|
|
||
| .. _Google Cloud SDK: https://cloud.google.com/sdk/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # This file is used to generate README.rst | ||
|
|
||
| product: | ||
| name: Google Cloud Data Labeling Service | ||
| short_name: Cloud Data Labeling | ||
| url: https://cloud.google.com/data-labeling/docs/ | ||
| description: > | ||
| `Google Cloud Data Labeling Service`_ allows developers to request having | ||
| human labelers label a collection of data that you plan to use to train a | ||
| custom machine learning model. | ||
|
|
||
| setup: | ||
| - auth | ||
| - install_deps | ||
|
|
||
| cloud_client_library: true | ||
|
|
||
| folder: datalabeling |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| #!/usr/bin/env python | ||
|
|
||
| # Copyright 2022 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import argparse | ||
| import os | ||
|
|
||
| from google.api_core.client_options import ClientOptions | ||
|
|
||
|
|
||
| # [START datalabeling_create_annotation_spec_set_beta] | ||
| def create_annotation_spec_set(project_id): | ||
| """Creates a data labeling annotation spec set for the given | ||
| Google Cloud project. | ||
| """ | ||
| from google.cloud import datalabeling_v1beta1 as datalabeling | ||
|
|
||
| client = datalabeling.DataLabelingServiceClient() | ||
| # [END datalabeling_create_annotation_spec_set_beta] | ||
| # If provided, use a provided test endpoint - this will prevent tests on | ||
| # this snippet from triggering any action by a real human | ||
| if "DATALABELING_ENDPOINT" in os.environ: | ||
| opts = ClientOptions(api_endpoint=os.getenv("DATALABELING_ENDPOINT")) | ||
| client = datalabeling.DataLabelingServiceClient(client_options=opts) | ||
| # [START datalabeling_create_annotation_spec_set_beta] | ||
|
|
||
| project_path = f"projects/{project_id}" | ||
|
|
||
| annotation_spec_1 = datalabeling.AnnotationSpec( | ||
| display_name="label_1", description="label_description_1" | ||
| ) | ||
|
|
||
| annotation_spec_2 = datalabeling.AnnotationSpec( | ||
| display_name="label_2", description="label_description_2" | ||
| ) | ||
|
|
||
| annotation_spec_set = datalabeling.AnnotationSpecSet( | ||
| display_name="YOUR_ANNOTATION_SPEC_SET_DISPLAY_NAME", | ||
| description="YOUR_DESCRIPTION", | ||
| annotation_specs=[annotation_spec_1, annotation_spec_2], | ||
| ) | ||
|
|
||
| response = client.create_annotation_spec_set( | ||
| request={"parent": project_path, "annotation_spec_set": annotation_spec_set} | ||
| ) | ||
|
|
||
| # The format of the resource name: | ||
| # project_id/{project_id}/annotationSpecSets/{annotationSpecSets_id} | ||
| print("The annotation_spec_set resource name: {}".format(response.name)) | ||
| print("Display name: {}".format(response.display_name)) | ||
| print("Description: {}".format(response.description)) | ||
| print("Annotation specs:") | ||
| for annotation_spec in response.annotation_specs: | ||
| print("\tDisplay name: {}".format(annotation_spec.display_name)) | ||
| print("\tDescription: {}\n".format(annotation_spec.description)) | ||
|
|
||
| return response | ||
|
|
||
|
|
||
| # [END datalabeling_create_annotation_spec_set_beta] | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| parser = argparse.ArgumentParser( | ||
| description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter | ||
| ) | ||
|
|
||
| parser.add_argument("--project-id", help="Project ID. Required.", required=True) | ||
|
|
||
| args = parser.parse_args() | ||
|
|
||
| create_annotation_spec_set(args.project_id) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| #!/usr/bin/env python | ||
|
|
||
| # Copyright 2022 Google, Inc | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import os | ||
|
|
||
| import backoff | ||
| from google.api_core.exceptions import ServerError | ||
| import pytest | ||
|
|
||
| import create_annotation_spec_set | ||
| import testing_lib | ||
|
|
||
| PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def cleaner(): | ||
| resource_names = [] | ||
|
|
||
| yield resource_names | ||
|
|
||
| for resource_name in resource_names: | ||
| testing_lib.delete_annotation_spec_set(resource_name) | ||
|
|
||
|
|
||
| @pytest.mark.skip(reason="service is limited due to covid") | ||
| def test_create_annotation_spec_set(cleaner, capsys): | ||
| @backoff.on_exception( | ||
| backoff.expo, ServerError, max_time=testing_lib.RETRY_DEADLINE | ||
| ) | ||
| def run_sample(): | ||
| return create_annotation_spec_set.create_annotation_spec_set(PROJECT_ID) | ||
|
|
||
| response = run_sample() | ||
|
|
||
| # For cleanup | ||
| cleaner.append(response.name) | ||
|
|
||
| out, _ = capsys.readouterr() | ||
| assert "The annotation_spec_set resource name:" in out |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| #!/usr/bin/env python | ||
|
|
||
| # Copyright 2022 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import argparse | ||
| import os | ||
|
|
||
| from google.api_core.client_options import ClientOptions | ||
|
|
||
|
|
||
| # [START datalabeling_create_instruction_beta] | ||
| def create_instruction(project_id, data_type, instruction_gcs_uri): | ||
| """Creates a data labeling PDF instruction for the given Google Cloud | ||
| project. The PDF file should be uploaded to the project in | ||
| Google Cloud Storage. | ||
| """ | ||
| from google.cloud import datalabeling_v1beta1 as datalabeling | ||
|
|
||
| client = datalabeling.DataLabelingServiceClient() | ||
| # [END datalabeling_create_instruction_beta] | ||
| # If provided, use a provided test endpoint - this will prevent tests on | ||
| # this snippet from triggering any action by a real human | ||
| if "DATALABELING_ENDPOINT" in os.environ: | ||
| opts = ClientOptions(api_endpoint=os.getenv("DATALABELING_ENDPOINT")) | ||
| client = datalabeling.DataLabelingServiceClient(client_options=opts) | ||
| # [START datalabeling_create_instruction_beta] | ||
|
|
||
| project_path = f"projects/{project_id}" | ||
|
|
||
| pdf_instruction = datalabeling.PdfInstruction(gcs_file_uri=instruction_gcs_uri) | ||
|
|
||
| instruction = datalabeling.Instruction( | ||
| display_name="YOUR_INSTRUCTION_DISPLAY_NAME", | ||
| description="YOUR_DESCRIPTION", | ||
| data_type=data_type, | ||
| pdf_instruction=pdf_instruction, | ||
| ) | ||
|
|
||
| operation = client.create_instruction( | ||
| request={"parent": project_path, "instruction": instruction} | ||
| ) | ||
|
|
||
| result = operation.result() | ||
|
|
||
| # The format of the resource name: | ||
| # project_id/{project_id}/instruction/{instruction_id} | ||
| print("The instruction resource name: {}".format(result.name)) | ||
| print("Display name: {}".format(result.display_name)) | ||
| print("Description: {}".format(result.description)) | ||
| print("Create time:") | ||
| print("\tseconds: {}".format(result.create_time.timestamp_pb().seconds)) | ||
| print("\tnanos: {}".format(result.create_time.timestamp_pb().nanos)) | ||
| print("Data type: {}".format(datalabeling.DataType(result.data_type).name)) | ||
| print("Pdf instruction:") | ||
| print("\tGcs file uri: {}\n".format(result.pdf_instruction.gcs_file_uri)) | ||
|
|
||
| return result | ||
|
|
||
|
|
||
| # [END datalabeling_create_instruction_beta] | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| parser = argparse.ArgumentParser( | ||
| description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter | ||
| ) | ||
|
|
||
| parser.add_argument("--project-id", help="Project ID. Required.", required=True) | ||
|
|
||
| parser.add_argument( | ||
| "--data-type", | ||
| help="Data type. Only support IMAGE, VIDEO, TEXT and AUDIO. Required.", | ||
| required=True, | ||
| ) | ||
|
|
||
| parser.add_argument( | ||
| "--instruction-gcs-uri", | ||
| help="The URI of Google Cloud Storage of the instruction. Required.", | ||
| required=True, | ||
| ) | ||
|
|
||
| args = parser.parse_args() | ||
|
|
||
| create_instruction(args.project_id, args.data_type, args.instruction_gcs_uri) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.