From 0b461ae63da268c3ac173261bc3ee11b79f4fc21 Mon Sep 17 00:00:00 2001 From: Gus Class Date: Fri, 5 May 2017 10:58:17 -0700 Subject: [PATCH 01/34] Adds tutorials using Cloud Client [(#930)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/930) * Adds tutorials. * Removes unused enumerate --- samples/labels/README.md | 29 ++++++++++++ samples/labels/labels.py | 80 +++++++++++++++++++++++++++++++++ samples/labels/labels_test.py | 32 +++++++++++++ samples/labels/requirements.txt | 1 + 4 files changed, 142 insertions(+) create mode 100644 samples/labels/README.md create mode 100644 samples/labels/labels.py create mode 100644 samples/labels/labels_test.py create mode 100644 samples/labels/requirements.txt diff --git a/samples/labels/README.md b/samples/labels/README.md new file mode 100644 index 00000000..20d87e76 --- /dev/null +++ b/samples/labels/README.md @@ -0,0 +1,29 @@ +# Google Cloud Video Intelligence + +Demonstrates label detection using the Google Cloud Video Intelligence API. + +## Setup +Please follow the [Set Up Your Project](https://cloud.google.com/video-intelligence/docs/getting-started#set_up_your_project) +steps in the Quickstart doc to create a project and enable the Google Cloud +Video Intelligence API. Following those steps, make sure that you +[Set Up a Service Account](https://cloud.google.com/video-intelligence/docs/common/auth#set_up_a_service_account), +and export the following environment variable: + +``` +export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your-project-credentials.json +``` + +## Run the sample + +Install [pip](https://pip.pypa.io/en/stable/installing) if not already installed. + +Install the necessary libraries using pip: + +```sh +$ pip install -r requirements.txt +``` + +Run the sample, for example: +``` +python labels.py gs://cloud-ml-sandbox/video/chicago.mp4 +``` diff --git a/samples/labels/labels.py b/samples/labels/labels.py new file mode 100644 index 00000000..c879be19 --- /dev/null +++ b/samples/labels/labels.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python + +# Copyright 2017 Google Inc. All Rights Reserved. +# +# 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. + +"""This application demonstrates how to perform basic operations with the +Google Cloud Video Intelligence API. + +For more information, check out the documentation at +https://cloud.google.com/videointelligence/docs. +""" + +# [START full_tutorial] +# [START imports] +import argparse +import sys +import time + +from google.cloud.gapic.videointelligence.v1beta1 import enums +from google.cloud.gapic.videointelligence.v1beta1 import ( + video_intelligence_service_client) +# [END imports] + + +def analyze_labels(path): + """ Detects labels given a GCS path. """ + # [START construct_request] + video_client = (video_intelligence_service_client. + VideoIntelligenceServiceClient()) + features = [enums.Feature.LABEL_DETECTION] + operation = video_client.annotate_video(path, features) + # [END construct_request] + print('\nProcessing video for label annotations:') + + # [START check_operation] + while not operation.done(): + sys.stdout.write('.') + sys.stdout.flush() + time.sleep(20) + + print('\nFinished processing.') + # [END check_operation] + + # [START parse_response] + results = operation.result().annotation_results[0] + + for label in results.label_annotations: + print('Label description: {}'.format(label.description)) + print('Locations:') + + for l, location in enumerate(label.locations): + print('\t{}: {} to {}'.format( + l, + location.segment.start_time_offset, + location.segment.end_time_offset)) + # [END parse_response] + + +if __name__ == '__main__': + # [START running_app] + parser = argparse.ArgumentParser( + description=__doc__, + formatter_class=argparse.RawDescriptionHelpFormatter) + parser.add_argument('path', help='GCS file path for label detection.') + args = parser.parse_args() + + analyze_labels(args.path) + # [END running_app] +# [END full_tutorial] diff --git a/samples/labels/labels_test.py b/samples/labels/labels_test.py new file mode 100644 index 00000000..cd571b08 --- /dev/null +++ b/samples/labels/labels_test.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python + +# Copyright 2017 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 pytest + +import labels + +BUCKET = os.environ['CLOUD_STORAGE_BUCKET'] +LABELS_FILE_PATH = '/video/cat.mp4' + + +@pytest.mark.slow +def test_feline_video_labels(capsys): + labels.analyze_labels( + 'gs://{}{}'.format(BUCKET, LABELS_FILE_PATH)) + out, _ = capsys.readouterr() + assert 'Whiskers' in out diff --git a/samples/labels/requirements.txt b/samples/labels/requirements.txt new file mode 100644 index 00000000..ba92ac97 --- /dev/null +++ b/samples/labels/requirements.txt @@ -0,0 +1 @@ +https://storage.googleapis.com/videointelligence-alpha/videointelligence-python.zip From ab4b78e1f961e913490741fc0eb9432d3cd9cadf Mon Sep 17 00:00:00 2001 From: Gus Class Date: Thu, 18 May 2017 16:01:37 -0700 Subject: [PATCH 02/34] Adds new examples, replaces markdown with restructured text [(#945)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/945) * Adds new examples, replaces markdown with restructured text * Address review feedback * Use videos from pubilc bucket, update to new client library. * Style nit --- samples/labels/README.md | 29 --------- samples/labels/README.rst | 120 +++++++++++++++++++++++++++++++++++ samples/labels/README.rst.in | 20 ++++++ samples/labels/labels.py | 5 ++ 4 files changed, 145 insertions(+), 29 deletions(-) delete mode 100644 samples/labels/README.md create mode 100644 samples/labels/README.rst create mode 100644 samples/labels/README.rst.in diff --git a/samples/labels/README.md b/samples/labels/README.md deleted file mode 100644 index 20d87e76..00000000 --- a/samples/labels/README.md +++ /dev/null @@ -1,29 +0,0 @@ -# Google Cloud Video Intelligence - -Demonstrates label detection using the Google Cloud Video Intelligence API. - -## Setup -Please follow the [Set Up Your Project](https://cloud.google.com/video-intelligence/docs/getting-started#set_up_your_project) -steps in the Quickstart doc to create a project and enable the Google Cloud -Video Intelligence API. Following those steps, make sure that you -[Set Up a Service Account](https://cloud.google.com/video-intelligence/docs/common/auth#set_up_a_service_account), -and export the following environment variable: - -``` -export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your-project-credentials.json -``` - -## Run the sample - -Install [pip](https://pip.pypa.io/en/stable/installing) if not already installed. - -Install the necessary libraries using pip: - -```sh -$ pip install -r requirements.txt -``` - -Run the sample, for example: -``` -python labels.py gs://cloud-ml-sandbox/video/chicago.mp4 -``` diff --git a/samples/labels/README.rst b/samples/labels/README.rst new file mode 100644 index 00000000..0f93579a --- /dev/null +++ b/samples/labels/README.rst @@ -0,0 +1,120 @@ +.. This file is automatically generated. Do not edit this file directly. + +Google Cloud Video Intelligence API Python Samples +=============================================================================== + +This directory contains samples for Google Cloud Video Intelligence API. `Google Cloud Video Intelligence API`_ allows developers to easily integrate feature detection in video. + + + + +.. _Google Cloud Video Intelligence API: https://cloud.google.com/video-intelligence/docs + +Setup +------------------------------------------------------------------------------- + + +Authentication +++++++++++++++ + +Authentication is typically done through `Application Default Credentials`_, +which means you do not have to change the code to authenticate as long as +your environment has credentials. You have a few options for setting up +authentication: + +#. When running locally, use the `Google Cloud SDK`_ + + .. code-block:: bash + + gcloud auth application-default login + + +#. When running on App Engine or Compute Engine, credentials are already + set-up. However, you may need to configure your Compute Engine instance + with `additional scopes`_. + +#. You can create a `Service Account key file`_. This file can be used to + authenticate to Google Cloud Platform services from any environment. To use + the file, set the ``GOOGLE_APPLICATION_CREDENTIALS`` environment variable to + the path to the key file, for example: + + .. code-block:: bash + + export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account.json + +.. _Application Default Credentials: https://cloud.google.com/docs/authentication#getting_credentials_for_server-centric_flow +.. _additional scopes: https://cloud.google.com/compute/docs/authentication#using +.. _Service Account key file: https://developers.google.com/identity/protocols/OAuth2ServiceAccount#creatinganaccount + +Install Dependencies +++++++++++++++++++++ + +#. Install `pip`_ and `virtualenv`_ if you do not already have them. + +#. 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/ + +Samples +------------------------------------------------------------------------------- + +labels ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + + +To run this sample: + +.. code-block:: bash + + $ python labels.py + + usage: labels.py [-h] path + + This application demonstrates how to perform basic operations with the + Google Cloud Video Intelligence API. + + For more information, check out the documentation at + https://cloud.google.com/videointelligence/docs. + + Usage Example: + + python labels.py gs://cloud-ml-sandbox/video/chicago.mp4 + + positional arguments: + path GCS file path for label detection. + + optional arguments: + -h, --help show this help message and exit + + + + +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/ \ No newline at end of file diff --git a/samples/labels/README.rst.in b/samples/labels/README.rst.in new file mode 100644 index 00000000..d5755799 --- /dev/null +++ b/samples/labels/README.rst.in @@ -0,0 +1,20 @@ +# This file is used to generate README.rst + +product: + name: Google Cloud Video Intelligence API + short_name: Cloud Video Intelligence API + url: https://cloud.google.com/video-intelligence/docs + description: > + `Google Cloud Video Intelligence API`_ allows developers to easily + integrate feature detection in video. + +setup: +- auth +- install_deps + +samples: +- name: labels + file: labels.py + show_help: True + +cloud_client_library: true diff --git a/samples/labels/labels.py b/samples/labels/labels.py index c879be19..7e0f9a0e 100644 --- a/samples/labels/labels.py +++ b/samples/labels/labels.py @@ -19,6 +19,11 @@ For more information, check out the documentation at https://cloud.google.com/videointelligence/docs. + +Usage Example: + + python labels.py gs://cloud-ml-sandbox/video/chicago.mp4 + """ # [START full_tutorial] From 9bd3074027dc223be0462d4a9ca63516b35c5380 Mon Sep 17 00:00:00 2001 From: Gus Class Date: Thu, 18 May 2017 16:44:27 -0700 Subject: [PATCH 03/34] Updates requirements [(#952)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/952) --- samples/labels/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/labels/requirements.txt b/samples/labels/requirements.txt index ba92ac97..b2aa05b6 100644 --- a/samples/labels/requirements.txt +++ b/samples/labels/requirements.txt @@ -1 +1 @@ -https://storage.googleapis.com/videointelligence-alpha/videointelligence-python.zip +google-cloud-videointelligence==0.25.0 From abd615bb2ade4a3d2c7d072debb8961a96a2f5fa Mon Sep 17 00:00:00 2001 From: Bill Prin Date: Tue, 23 May 2017 17:01:25 -0700 Subject: [PATCH 04/34] Fix README rst links [(#962)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/962) * Fix README rst links * Update all READMEs --- samples/labels/README.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/labels/README.rst b/samples/labels/README.rst index 0f93579a..431f5325 100644 --- a/samples/labels/README.rst +++ b/samples/labels/README.rst @@ -109,11 +109,11 @@ 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: +.. _Google Cloud Client Library for Python: https://googlecloudplatform.github.io/google-cloud-python/ -.. browse the source: +.. _browse the source: https://github.com/GoogleCloudPlatform/google-cloud-python -.. report issues: +.. _report issues: https://github.com/GoogleCloudPlatform/google-cloud-python/issues From 26583e546dd465d90c62e1984fb7f14374331a46 Mon Sep 17 00:00:00 2001 From: DPE bot Date: Tue, 29 Aug 2017 16:53:02 -0700 Subject: [PATCH 05/34] Auto-update dependencies. [(#1093)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1093) * Auto-update dependencies. * Fix storage notification poll sample Change-Id: I6afbc79d15e050531555e4c8e51066996717a0f3 * Fix spanner samples Change-Id: I40069222c60d57e8f3d3878167591af9130895cb * Drop coverage because it's not useful Change-Id: Iae399a7083d7866c3c7b9162d0de244fbff8b522 * Try again to fix flaky logging test Change-Id: I6225c074701970c17c426677ef1935bb6d7e36b4 --- samples/labels/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/labels/requirements.txt b/samples/labels/requirements.txt index b2aa05b6..28c02728 100644 --- a/samples/labels/requirements.txt +++ b/samples/labels/requirements.txt @@ -1 +1 @@ -google-cloud-videointelligence==0.25.0 +google-cloud-videointelligence==0.26.0 From 2e034cb99e3708f630d70070b14b37ca338ee707 Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Mon, 18 Sep 2017 11:04:05 -0700 Subject: [PATCH 06/34] Update all generated readme auth instructions [(#1121)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1121) Change-Id: I03b5eaef8b17ac3dc3c0339fd2c7447bd3e11bd2 --- samples/labels/README.rst | 32 +++++--------------------------- 1 file changed, 5 insertions(+), 27 deletions(-) diff --git a/samples/labels/README.rst b/samples/labels/README.rst index 431f5325..74dccd38 100644 --- a/samples/labels/README.rst +++ b/samples/labels/README.rst @@ -17,34 +17,12 @@ Setup Authentication ++++++++++++++ -Authentication is typically done through `Application Default Credentials`_, -which means you do not have to change the code to authenticate as long as -your environment has credentials. You have a few options for setting up -authentication: +This sample requires you to have authentication setup. Refer to the +`Authentication Getting Started Guide`_ for instructions on setting up +credentials for applications. -#. When running locally, use the `Google Cloud SDK`_ - - .. code-block:: bash - - gcloud auth application-default login - - -#. When running on App Engine or Compute Engine, credentials are already - set-up. However, you may need to configure your Compute Engine instance - with `additional scopes`_. - -#. You can create a `Service Account key file`_. This file can be used to - authenticate to Google Cloud Platform services from any environment. To use - the file, set the ``GOOGLE_APPLICATION_CREDENTIALS`` environment variable to - the path to the key file, for example: - - .. code-block:: bash - - export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account.json - -.. _Application Default Credentials: https://cloud.google.com/docs/authentication#getting_credentials_for_server-centric_flow -.. _additional scopes: https://cloud.google.com/compute/docs/authentication#using -.. _Service Account key file: https://developers.google.com/identity/protocols/OAuth2ServiceAccount#creatinganaccount +.. _Authentication Getting Started Guide: + https://cloud.google.com/docs/authentication/getting-started Install Dependencies ++++++++++++++++++++ From cab45cc5ca076c0f78791889dadb1738b50b8d1b Mon Sep 17 00:00:00 2001 From: DPE bot Date: Tue, 19 Sep 2017 09:34:15 -0700 Subject: [PATCH 07/34] Auto-update dependencies. [(#1123)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1123) --- samples/labels/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/labels/requirements.txt b/samples/labels/requirements.txt index 28c02728..d3b18758 100644 --- a/samples/labels/requirements.txt +++ b/samples/labels/requirements.txt @@ -1 +1 @@ -google-cloud-videointelligence==0.26.0 +google-cloud-videointelligence==0.27.2 From c4d1d3295247072e63f1330467cada4f6c1e9964 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Tue, 19 Sep 2017 14:42:07 -0700 Subject: [PATCH 08/34] Video v1beta2 [(#1088)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1088) * update analyze_safe_search * update analyze_shots * update explicit_content_detection and test * update fece detection * update label detection (path) * update label detection (file) * flake * safe search --> explicit content * update faces tutorial * update client library quickstart * update shotchange tutorial * update labels tutorial * correct spelling * correction start_time_offset * import order * rebased --- samples/labels/labels.py | 34 ++++++++++++++++++++-------------- samples/labels/labels_test.py | 5 ++--- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/samples/labels/labels.py b/samples/labels/labels.py index 7e0f9a0e..5f45b831 100644 --- a/samples/labels/labels.py +++ b/samples/labels/labels.py @@ -32,17 +32,15 @@ import sys import time -from google.cloud.gapic.videointelligence.v1beta1 import enums -from google.cloud.gapic.videointelligence.v1beta1 import ( - video_intelligence_service_client) +from google.cloud import videointelligence_v1beta2 +from google.cloud.videointelligence_v1beta2 import enums # [END imports] def analyze_labels(path): """ Detects labels given a GCS path. """ # [START construct_request] - video_client = (video_intelligence_service_client. - VideoIntelligenceServiceClient()) + video_client = videointelligence_v1beta2.VideoIntelligenceServiceClient() features = [enums.Feature.LABEL_DETECTION] operation = video_client.annotate_video(path, features) # [END construct_request] @@ -60,15 +58,23 @@ def analyze_labels(path): # [START parse_response] results = operation.result().annotation_results[0] - for label in results.label_annotations: - print('Label description: {}'.format(label.description)) - print('Locations:') - - for l, location in enumerate(label.locations): - print('\t{}: {} to {}'.format( - l, - location.segment.start_time_offset, - location.segment.end_time_offset)) + for i, segment_label in enumerate(results.segment_label_annotations): + print('Video label description: {}'.format( + segment_label.entity.description)) + for category_entity in segment_label.category_entities: + print('\tLabel category description: {}'.format( + category_entity.description)) + + for i, segment in enumerate(segment_label.segments): + start_time = (segment.segment.start_time_offset.seconds + + segment.segment.start_time_offset.nanos / 1e9) + end_time = (segment.segment.end_time_offset.seconds + + segment.segment.end_time_offset.nanos / 1e9) + positions = '{}s to {}s'.format(start_time, end_time) + confidence = segment.confidence + print('\tSegment {}: {}'.format(i, positions)) + print('\tConfidence: {}'.format(confidence)) + print('\n') # [END parse_response] diff --git a/samples/labels/labels_test.py b/samples/labels/labels_test.py index cd571b08..31a68358 100644 --- a/samples/labels/labels_test.py +++ b/samples/labels/labels_test.py @@ -15,10 +15,9 @@ # limitations under the License. import os - +import labels import pytest -import labels BUCKET = os.environ['CLOUD_STORAGE_BUCKET'] LABELS_FILE_PATH = '/video/cat.mp4' @@ -29,4 +28,4 @@ def test_feline_video_labels(capsys): labels.analyze_labels( 'gs://{}{}'.format(BUCKET, LABELS_FILE_PATH)) out, _ = capsys.readouterr() - assert 'Whiskers' in out + assert 'Video label description: cat' in out From bd8edbd0dd3dc5be68a109575c6069f862e04149 Mon Sep 17 00:00:00 2001 From: michaelawyu Date: Thu, 12 Oct 2017 10:16:11 -0700 Subject: [PATCH 09/34] Added Link to Python Setup Guide [(#1158)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1158) * Update Readme.rst to add Python setup guide As requested in b/64770713. This sample is linked in documentation https://cloud.google.com/bigtable/docs/scaling, and it would make more sense to update the guide here than in the documentation. * Update README.rst * Update README.rst * Update README.rst * Update README.rst * Update README.rst * Update install_deps.tmpl.rst * Updated readmegen scripts and re-generated related README files * Fixed the lint error --- samples/labels/README.rst | 5 ++++- samples/labels/labels_test.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/samples/labels/README.rst b/samples/labels/README.rst index 74dccd38..54b8f851 100644 --- a/samples/labels/README.rst +++ b/samples/labels/README.rst @@ -27,7 +27,10 @@ credentials for applications. Install Dependencies ++++++++++++++++++++ -#. Install `pip`_ and `virtualenv`_ if you do not already have them. +#. 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+. diff --git a/samples/labels/labels_test.py b/samples/labels/labels_test.py index 31a68358..2022a116 100644 --- a/samples/labels/labels_test.py +++ b/samples/labels/labels_test.py @@ -15,8 +15,8 @@ # limitations under the License. import os -import labels import pytest +import labels BUCKET = os.environ['CLOUD_STORAGE_BUCKET'] From 1489930a66e3d4a601ae0eb5c4ee7363185cc44e Mon Sep 17 00:00:00 2001 From: Perry Stoll Date: Thu, 12 Oct 2017 13:16:50 -0400 Subject: [PATCH 10/34] Tweak doc/help strings for sample tools [(#1160)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1160) * Corrected copy-paste on doc string * Updated doc/help string to be more specific to labels tool * Made shotchange doc/help string more specific * Tweaked doc/help string to indicate no arg expected * Adjusted import order to satisfy flake8 * Wrapped doc string to 79 chars to flake8 correctly * Adjusted import order to pass flake8 test --- samples/labels/labels.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/samples/labels/labels.py b/samples/labels/labels.py index 5f45b831..b5c2f42e 100644 --- a/samples/labels/labels.py +++ b/samples/labels/labels.py @@ -14,8 +14,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""This application demonstrates how to perform basic operations with the -Google Cloud Video Intelligence API. +"""This application demonstrates how to detect labels from a video +based on the image content with the Google Cloud Video Intelligence +API. For more information, check out the documentation at https://cloud.google.com/videointelligence/docs. From 5739425cf79626755bfa32932233efbe431474d6 Mon Sep 17 00:00:00 2001 From: DPE bot Date: Wed, 1 Nov 2017 12:30:10 -0700 Subject: [PATCH 11/34] Auto-update dependencies. [(#1186)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1186) --- samples/labels/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/labels/requirements.txt b/samples/labels/requirements.txt index d3b18758..481c80c4 100644 --- a/samples/labels/requirements.txt +++ b/samples/labels/requirements.txt @@ -1 +1 @@ -google-cloud-videointelligence==0.27.2 +google-cloud-videointelligence==0.28.0 From 5132d60c537f8ba1add461fe99d8f7b79fa37ed2 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Wed, 29 Nov 2017 15:39:47 -0800 Subject: [PATCH 12/34] update samples to v1 [(#1221)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1221) * update samples to v1 * replace while loop with operation.result(timeout) * addressing review comments * flake * flake --- samples/labels/labels.py | 22 +++++++--------------- samples/labels/labels_test.py | 2 ++ samples/labels/requirements.txt | 2 +- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/samples/labels/labels.py b/samples/labels/labels.py index b5c2f42e..7721f364 100644 --- a/samples/labels/labels.py +++ b/samples/labels/labels.py @@ -30,36 +30,28 @@ # [START full_tutorial] # [START imports] import argparse -import sys -import time -from google.cloud import videointelligence_v1beta2 -from google.cloud.videointelligence_v1beta2 import enums +from google.cloud import videointelligence # [END imports] def analyze_labels(path): """ Detects labels given a GCS path. """ # [START construct_request] - video_client = videointelligence_v1beta2.VideoIntelligenceServiceClient() - features = [enums.Feature.LABEL_DETECTION] - operation = video_client.annotate_video(path, features) + video_client = videointelligence.VideoIntelligenceServiceClient() + features = [videointelligence.enums.Feature.LABEL_DETECTION] + operation = video_client.annotate_video(path, features=features) # [END construct_request] print('\nProcessing video for label annotations:') # [START check_operation] - while not operation.done(): - sys.stdout.write('.') - sys.stdout.flush() - time.sleep(20) - + result = operation.result(timeout=90) print('\nFinished processing.') # [END check_operation] # [START parse_response] - results = operation.result().annotation_results[0] - - for i, segment_label in enumerate(results.segment_label_annotations): + segment_labels = result.annotation_results[0].segment_label_annotations + for i, segment_label in enumerate(segment_labels): print('Video label description: {}'.format( segment_label.entity.description)) for category_entity in segment_label.category_entities: diff --git a/samples/labels/labels_test.py b/samples/labels/labels_test.py index 2022a116..0472e219 100644 --- a/samples/labels/labels_test.py +++ b/samples/labels/labels_test.py @@ -15,7 +15,9 @@ # limitations under the License. import os + import pytest + import labels diff --git a/samples/labels/requirements.txt b/samples/labels/requirements.txt index 481c80c4..747f3c7a 100644 --- a/samples/labels/requirements.txt +++ b/samples/labels/requirements.txt @@ -1 +1 @@ -google-cloud-videointelligence==0.28.0 +google-cloud-videointelligence==1.0.0 From c0d137663cc5090432aecf2775f9f7e7eb1a5e79 Mon Sep 17 00:00:00 2001 From: michaelawyu Date: Thu, 7 Dec 2017 10:34:29 -0800 Subject: [PATCH 13/34] Added "Open in Cloud Shell" buttons to README files [(#1254)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1254) --- samples/labels/README.rst | 26 ++++++++++++++++++-------- samples/labels/README.rst.in | 2 ++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/samples/labels/README.rst b/samples/labels/README.rst index 54b8f851..7eae1480 100644 --- a/samples/labels/README.rst +++ b/samples/labels/README.rst @@ -3,6 +3,10 @@ Google Cloud Video Intelligence API 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=video/cloud-client/labels/README.rst + + This directory contains samples for Google Cloud Video Intelligence API. `Google Cloud Video Intelligence API`_ allows developers to easily integrate feature detection in video. @@ -54,6 +58,10 @@ Samples labels +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +.. 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=video/cloud-client/labels/labels.py;video/cloud-client/labels/README.rst + + To run this sample: @@ -63,26 +71,28 @@ To run this sample: $ python labels.py usage: labels.py [-h] path - - This application demonstrates how to perform basic operations with the - Google Cloud Video Intelligence API. - + + This application demonstrates how to detect labels from a video + based on the image content with the Google Cloud Video Intelligence + API. + For more information, check out the documentation at https://cloud.google.com/videointelligence/docs. - + Usage Example: - + python labels.py gs://cloud-ml-sandbox/video/chicago.mp4 - + positional arguments: path GCS file path for label detection. - + optional arguments: -h, --help show this help message and exit + The client library ------------------------------------------------------------------------------- diff --git a/samples/labels/README.rst.in b/samples/labels/README.rst.in index d5755799..2d6b97cf 100644 --- a/samples/labels/README.rst.in +++ b/samples/labels/README.rst.in @@ -18,3 +18,5 @@ samples: show_help: True cloud_client_library: true + +folder: video/cloud-client/labels \ No newline at end of file From 00dcf93acb6e845e705672d7f1f9fd07f06dbb97 Mon Sep 17 00:00:00 2001 From: DPE bot Date: Mon, 5 Mar 2018 12:28:55 -0800 Subject: [PATCH 14/34] Auto-update dependencies. [(#1377)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1377) * Auto-update dependencies. * Update requirements.txt --- samples/labels/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/labels/requirements.txt b/samples/labels/requirements.txt index 747f3c7a..e2ad27b8 100644 --- a/samples/labels/requirements.txt +++ b/samples/labels/requirements.txt @@ -1 +1 @@ -google-cloud-videointelligence==1.0.0 +google-cloud-videointelligence==1.0.1 From abd0c62423f68eb2e10f3711d1578ec8cf352246 Mon Sep 17 00:00:00 2001 From: DPE bot Date: Mon, 2 Apr 2018 02:51:10 -0700 Subject: [PATCH 15/34] Auto-update dependencies. --- samples/labels/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/labels/requirements.txt b/samples/labels/requirements.txt index e2ad27b8..bf3b2da4 100644 --- a/samples/labels/requirements.txt +++ b/samples/labels/requirements.txt @@ -1 +1 @@ -google-cloud-videointelligence==1.0.1 +google-cloud-videointelligence==1.1.0 From ee189b8a9f6c179723209cf30e70e5ae07ab29ba Mon Sep 17 00:00:00 2001 From: chenyumic Date: Fri, 6 Apr 2018 22:57:36 -0700 Subject: [PATCH 16/34] Regenerate the README files and fix the Open in Cloud Shell link for some samples [(#1441)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1441) --- samples/labels/README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/labels/README.rst b/samples/labels/README.rst index 7eae1480..2b36e9b3 100644 --- a/samples/labels/README.rst +++ b/samples/labels/README.rst @@ -12,7 +12,7 @@ This directory contains samples for Google Cloud Video Intelligence API. `Google -.. _Google Cloud Video Intelligence API: https://cloud.google.com/video-intelligence/docs +.. _Google Cloud Video Intelligence API: https://cloud.google.com/video-intelligence/docs Setup ------------------------------------------------------------------------------- @@ -59,7 +59,7 @@ labels +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ .. 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=video/cloud-client/labels/labels.py;video/cloud-client/labels/README.rst + :target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=video/cloud-client/labels/labels.py,video/cloud-client/labels/README.rst From e006b6fef07df35ebf9226e085e583062021d88c Mon Sep 17 00:00:00 2001 From: Frank Natividad Date: Thu, 26 Apr 2018 10:26:41 -0700 Subject: [PATCH 17/34] Update READMEs to fix numbering and add git clone [(#1464)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1464) --- samples/labels/README.rst | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/samples/labels/README.rst b/samples/labels/README.rst index 2b36e9b3..ab919e7f 100644 --- a/samples/labels/README.rst +++ b/samples/labels/README.rst @@ -31,10 +31,16 @@ credentials for applications. 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 + .. _Python Development Environment Setup Guide: + https://cloud.google.com/python/setup #. Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+. From fae16696c58b1587702444635155cede70e0146a Mon Sep 17 00:00:00 2001 From: Alix Hamilton Date: Mon, 20 Aug 2018 12:26:42 -0700 Subject: [PATCH 18/34] Video Intelligence region tag update [(#1639)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1639) --- samples/labels/labels.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/samples/labels/labels.py b/samples/labels/labels.py index 7721f364..4a1cf767 100644 --- a/samples/labels/labels.py +++ b/samples/labels/labels.py @@ -27,29 +27,29 @@ """ -# [START full_tutorial] -# [START imports] +# [START video_label_tutorial] +# [START video_label_tutorial_imports] import argparse from google.cloud import videointelligence -# [END imports] +# [END video_label_tutorial_imports] def analyze_labels(path): """ Detects labels given a GCS path. """ - # [START construct_request] + # [START video_label_tutorial_construct_request] video_client = videointelligence.VideoIntelligenceServiceClient() features = [videointelligence.enums.Feature.LABEL_DETECTION] operation = video_client.annotate_video(path, features=features) - # [END construct_request] + # [END video_label_tutorial_construct_request] print('\nProcessing video for label annotations:') - # [START check_operation] + # [START video_label_tutorial_check_operation] result = operation.result(timeout=90) print('\nFinished processing.') - # [END check_operation] + # [END video_label_tutorial_check_operation] - # [START parse_response] + # [START video_label_tutorial_parse_response] segment_labels = result.annotation_results[0].segment_label_annotations for i, segment_label in enumerate(segment_labels): print('Video label description: {}'.format( @@ -68,11 +68,11 @@ def analyze_labels(path): print('\tSegment {}: {}'.format(i, positions)) print('\tConfidence: {}'.format(confidence)) print('\n') - # [END parse_response] + # [END video_label_tutorial_parse_response] if __name__ == '__main__': - # [START running_app] + # [START video_label_tutorial_run_application] parser = argparse.ArgumentParser( description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) @@ -80,5 +80,5 @@ def analyze_labels(path): args = parser.parse_args() analyze_labels(args.path) - # [END running_app] -# [END full_tutorial] + # [END video_label_tutorial_run_application] +# [END video_label_tutorial] From b89a697738bc192ad8cd27b7161a04f8edeee9d4 Mon Sep 17 00:00:00 2001 From: DPE bot Date: Tue, 28 Aug 2018 11:17:45 -0700 Subject: [PATCH 19/34] Auto-update dependencies. [(#1658)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1658) * Auto-update dependencies. * Rollback appengine/standard/bigquery/. * Rollback appengine/standard/iap/. * Rollback bigtable/metricscaler. * Rolledback appengine/flexible/datastore. * Rollback dataproc/ * Rollback jobs/api_client * Rollback vision/cloud-client. * Rollback functions/ocr/app. * Rollback iot/api-client/end_to_end_example. * Rollback storage/cloud-client. * Rollback kms/api-client. * Rollback dlp/ * Rollback bigquery/cloud-client. * Rollback iot/api-client/manager. * Rollback appengine/flexible/cloudsql_postgresql. --- samples/labels/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/labels/requirements.txt b/samples/labels/requirements.txt index bf3b2da4..3e462bd8 100644 --- a/samples/labels/requirements.txt +++ b/samples/labels/requirements.txt @@ -1 +1 @@ -google-cloud-videointelligence==1.1.0 +google-cloud-videointelligence==1.3.0 From 98cbb15df22928637cf0b93b16c7cfecb2a5ae55 Mon Sep 17 00:00:00 2001 From: Alix Hamilton Date: Wed, 10 Oct 2018 10:00:33 -0700 Subject: [PATCH 20/34] Use explicit URIs for Video Intelligence sample tests [(#1743)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1743) --- samples/labels/labels_test.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/samples/labels/labels_test.py b/samples/labels/labels_test.py index 0472e219..ae455b90 100644 --- a/samples/labels/labels_test.py +++ b/samples/labels/labels_test.py @@ -14,20 +14,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os - import pytest import labels -BUCKET = os.environ['CLOUD_STORAGE_BUCKET'] -LABELS_FILE_PATH = '/video/cat.mp4' - - @pytest.mark.slow def test_feline_video_labels(capsys): - labels.analyze_labels( - 'gs://{}{}'.format(BUCKET, LABELS_FILE_PATH)) + labels.analyze_labels('gs://demomaker/cat.mp4') out, _ = capsys.readouterr() assert 'Video label description: cat' in out From 835f8fd27ca011a5c1521658bcdde5c3addc2a0c Mon Sep 17 00:00:00 2001 From: DPE bot Date: Tue, 20 Nov 2018 15:40:29 -0800 Subject: [PATCH 21/34] Auto-update dependencies. [(#1846)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1846) ACK, merging. --- samples/labels/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/labels/requirements.txt b/samples/labels/requirements.txt index 3e462bd8..e678d25a 100644 --- a/samples/labels/requirements.txt +++ b/samples/labels/requirements.txt @@ -1 +1 @@ -google-cloud-videointelligence==1.3.0 +google-cloud-videointelligence==1.6.0 From 76adaf01b9503d454edbae17503edc73ba187d7e Mon Sep 17 00:00:00 2001 From: DPEBot Date: Wed, 6 Feb 2019 12:06:35 -0800 Subject: [PATCH 22/34] Auto-update dependencies. [(#1980)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1980) * Auto-update dependencies. * Update requirements.txt * Update requirements.txt --- samples/labels/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/labels/requirements.txt b/samples/labels/requirements.txt index e678d25a..0a5c79b1 100644 --- a/samples/labels/requirements.txt +++ b/samples/labels/requirements.txt @@ -1 +1 @@ -google-cloud-videointelligence==1.6.0 +google-cloud-videointelligence==1.6.1 From 0ea61930ef815da6fd484fc2d56b4d81e6b3b761 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Thu, 16 May 2019 15:35:02 -0700 Subject: [PATCH 23/34] =?UTF-8?q?replace=20demomaker=20with=20cloud-sample?= =?UTF-8?q?s-data/video=20for=20video=20intelligenc=E2=80=A6=20[(#2162)](h?= =?UTF-8?q?ttps://github.com/GoogleCloudPlatform/python-docs-samples/issue?= =?UTF-8?q?s/2162)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * replace demomaker with cloud-samples-data/video for video intelligence samples * flake --- samples/labels/labels_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/labels/labels_test.py b/samples/labels/labels_test.py index ae455b90..1249f5b9 100644 --- a/samples/labels/labels_test.py +++ b/samples/labels/labels_test.py @@ -21,6 +21,6 @@ @pytest.mark.slow def test_feline_video_labels(capsys): - labels.analyze_labels('gs://demomaker/cat.mp4') + labels.analyze_labels('gs://cloud-samples-data/video/cat.mp4') out, _ = capsys.readouterr() assert 'Video label description: cat' in out From 3c2662c963d8cddf63859cedf65e338b4f4a2bea Mon Sep 17 00:00:00 2001 From: Gus Class Date: Mon, 7 Oct 2019 15:45:22 -0700 Subject: [PATCH 24/34] Adds updates for samples profiler ... vision [(#2439)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/2439) --- samples/labels/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/labels/requirements.txt b/samples/labels/requirements.txt index 0a5c79b1..aa6b5613 100644 --- a/samples/labels/requirements.txt +++ b/samples/labels/requirements.txt @@ -1 +1 @@ -google-cloud-videointelligence==1.6.1 +google-cloud-videointelligence==1.11.0 From 67da47dfaec86de2cad2d1b5562eeeccb6971c80 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 20 Dec 2019 17:41:38 -0800 Subject: [PATCH 25/34] Auto-update dependencies. [(#2005)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/2005) * Auto-update dependencies. * Revert update of appengine/flexible/datastore. * revert update of appengine/flexible/scipy * revert update of bigquery/bqml * revert update of bigquery/cloud-client * revert update of bigquery/datalab-migration * revert update of bigtable/quickstart * revert update of compute/api * revert update of container_registry/container_analysis * revert update of dataflow/run_template * revert update of datastore/cloud-ndb * revert update of dialogflow/cloud-client * revert update of dlp * revert update of functions/imagemagick * revert update of functions/ocr/app * revert update of healthcare/api-client/fhir * revert update of iam/api-client * revert update of iot/api-client/gcs_file_to_device * revert update of iot/api-client/mqtt_example * revert update of language/automl * revert update of run/image-processing * revert update of vision/automl * revert update testing/requirements.txt * revert update of vision/cloud-client/detect * revert update of vision/cloud-client/product_search * revert update of jobs/v2/api_client * revert update of jobs/v3/api_client * revert update of opencensus * revert update of translate/cloud-client * revert update to speech/cloud-client Co-authored-by: Kurtis Van Gent <31518063+kurtisvg@users.noreply.github.com> Co-authored-by: Doug Mahugh --- samples/labels/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/labels/requirements.txt b/samples/labels/requirements.txt index aa6b5613..4e0b7df4 100644 --- a/samples/labels/requirements.txt +++ b/samples/labels/requirements.txt @@ -1 +1 @@ -google-cloud-videointelligence==1.11.0 +google-cloud-videointelligence==1.12.1 From c987844f848faa599a2a1688686a314639058b52 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Fri, 27 Mar 2020 17:19:58 +0100 Subject: [PATCH 26/34] chore(deps): update dependency google-cloud-videointelligence to v1.14.0 [(#3169)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/3169) --- samples/labels/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/labels/requirements.txt b/samples/labels/requirements.txt index 4e0b7df4..8b966916 100644 --- a/samples/labels/requirements.txt +++ b/samples/labels/requirements.txt @@ -1 +1 @@ -google-cloud-videointelligence==1.12.1 +google-cloud-videointelligence==1.14.0 From 8207cfd29add2da1f244988a368d2269e84edd74 Mon Sep 17 00:00:00 2001 From: Kurtis Van Gent <31518063+kurtisvg@users.noreply.github.com> Date: Wed, 1 Apr 2020 19:11:50 -0700 Subject: [PATCH 27/34] Simplify noxfile setup. [(#2806)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/2806) * chore(deps): update dependency requests to v2.23.0 * Simplify noxfile and add version control. * Configure appengine/standard to only test Python 2.7. * Update Kokokro configs to match noxfile. * Add requirements-test to each folder. * Remove Py2 versions from everything execept appengine/standard. * Remove conftest.py. * Remove appengine/standard/conftest.py * Remove 'no-sucess-flaky-report' from pytest.ini. * Add GAE SDK back to appengine/standard tests. * Fix typo. * Roll pytest to python 2 version. * Add a bunch of testing requirements. * Remove typo. * Add appengine lib directory back in. * Add some additional requirements. * Fix issue with flake8 args. * Even more requirements. * Readd appengine conftest.py. * Add a few more requirements. * Even more Appengine requirements. * Add webtest for appengine/standard/mailgun. * Add some additional requirements. * Add workaround for issue with mailjet-rest. * Add responses for appengine/standard/mailjet. Co-authored-by: Renovate Bot --- samples/labels/requirements-test.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 samples/labels/requirements-test.txt diff --git a/samples/labels/requirements-test.txt b/samples/labels/requirements-test.txt new file mode 100644 index 00000000..781d4326 --- /dev/null +++ b/samples/labels/requirements-test.txt @@ -0,0 +1 @@ +pytest==5.3.2 From cd88a29f26026f816f7a903cbc29bb559fe27896 Mon Sep 17 00:00:00 2001 From: Eric Schmidt Date: Tue, 9 Jun 2020 11:40:08 -0700 Subject: [PATCH 28/34] fix: changes positional to named pararameters in Video samples [(#4017)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4017) Changes calls to `VideoClient.annotate_video()` so that GCS URIs are provided as named parameters. Example: ``` operation = video_client.annotate_video(path, features=features) ``` Becomes: ``` operation = video_client.annotate_video(input_uri=path, features=features) ``` --- samples/labels/labels.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/labels/labels.py b/samples/labels/labels.py index 4a1cf767..cfb4ad0c 100644 --- a/samples/labels/labels.py +++ b/samples/labels/labels.py @@ -40,7 +40,7 @@ def analyze_labels(path): # [START video_label_tutorial_construct_request] video_client = videointelligence.VideoIntelligenceServiceClient() features = [videointelligence.enums.Feature.LABEL_DETECTION] - operation = video_client.annotate_video(path, features=features) + operation = video_client.annotate_video(input_uri=path, features=features) # [END video_label_tutorial_construct_request] print('\nProcessing video for label annotations:') From ef8cf11ec441544926f913bb420d912796b2a317 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Tue, 16 Jun 2020 17:20:10 +0200 Subject: [PATCH 29/34] Update dependency google-cloud-videointelligence to v1.15.0 [(#4041)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4041) This PR contains the following updates: | Package | Update | Change | |---|---|---| | [google-cloud-videointelligence](https://togithub.com/googleapis/python-videointelligence) | minor | `==1.14.0` -> `==1.15.0` | --- ### Release Notes
googleapis/python-videointelligence ### [`v1.15.0`](https://togithub.com/googleapis/python-videointelligence/blob/master/CHANGELOG.md#​1150-httpswwwgithubcomgoogleapispython-videointelligencecomparev1140v1150-2020-06-09) [Compare Source](https://togithub.com/googleapis/python-videointelligence/compare/v1.14.0...v1.15.0) ##### Features - add support for streaming automl action recognition in v1p3beta1; make 'features' a positional param for annotate_video in betas ([#​31](https://www.github.com/googleapis/python-videointelligence/issues/31)) ([586f920](https://www.github.com/googleapis/python-videointelligence/commit/586f920a1932e1a813adfed500502fba0ff5edb7)), closes [#​517](https://www.github.com/googleapis/python-videointelligence/issues/517) [#​538](https://www.github.com/googleapis/python-videointelligence/issues/538) [#​565](https://www.github.com/googleapis/python-videointelligence/issues/565) [#​576](https://www.github.com/googleapis/python-videointelligence/issues/576) [#​506](https://www.github.com/googleapis/python-videointelligence/issues/506) [#​586](https://www.github.com/googleapis/python-videointelligence/issues/586) [#​585](https://www.github.com/googleapis/python-videointelligence/issues/585)
--- ### Renovate configuration :date: **Schedule**: At any time (no schedule defined). :vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied. :recycle: **Rebasing**: Never, or you tick the rebase/retry checkbox. :no_bell: **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#GoogleCloudPlatform/python-docs-samples). --- samples/labels/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/labels/requirements.txt b/samples/labels/requirements.txt index 8b966916..5fdd76a3 100644 --- a/samples/labels/requirements.txt +++ b/samples/labels/requirements.txt @@ -1 +1 @@ -google-cloud-videointelligence==1.14.0 +google-cloud-videointelligence==1.15.0 From 1546e82c4ce52f0eac73d5f937b97f736946f923 Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Mon, 13 Jul 2020 00:46:30 +0200 Subject: [PATCH 30/34] chore(deps): update dependency pytest to v5.4.3 [(#4279)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4279) * chore(deps): update dependency pytest to v5.4.3 * specify pytest for python 2 in appengine Co-authored-by: Leah Cole --- samples/labels/requirements-test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/labels/requirements-test.txt b/samples/labels/requirements-test.txt index 781d4326..79738af5 100644 --- a/samples/labels/requirements-test.txt +++ b/samples/labels/requirements-test.txt @@ -1 +1 @@ -pytest==5.3.2 +pytest==5.4.3 From 56e9a8d1c89b408d83dd6a52dbe0e6a450fa721a Mon Sep 17 00:00:00 2001 From: WhiteSource Renovate Date: Sat, 1 Aug 2020 21:51:00 +0200 Subject: [PATCH 31/34] Update dependency pytest to v6 [(#4390)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/4390) --- samples/labels/requirements-test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/labels/requirements-test.txt b/samples/labels/requirements-test.txt index 79738af5..7e460c8c 100644 --- a/samples/labels/requirements-test.txt +++ b/samples/labels/requirements-test.txt @@ -1 +1 @@ -pytest==5.4.3 +pytest==6.0.1 From 4068e1639226d727ee9f9af1a8b57e1a5d03f168 Mon Sep 17 00:00:00 2001 From: Dan O'Meara Date: Thu, 1 Oct 2020 22:49:49 +0000 Subject: [PATCH 32/34] chore: adds samples templates --- .kokoro/samples/python3.6/common.cfg | 6 + .kokoro/samples/python3.7/common.cfg | 6 + .kokoro/samples/python3.8/common.cfg | 6 + noxfile.py | 2 +- samples/labels/README.rst | 22 ++- samples/labels/noxfile.py | 224 +++++++++++++++++++++++++++ synth.metadata | 12 +- 7 files changed, 269 insertions(+), 9 deletions(-) create mode 100644 samples/labels/noxfile.py diff --git a/.kokoro/samples/python3.6/common.cfg b/.kokoro/samples/python3.6/common.cfg index f2c35a39..3c29ddaa 100644 --- a/.kokoro/samples/python3.6/common.cfg +++ b/.kokoro/samples/python3.6/common.cfg @@ -13,6 +13,12 @@ env_vars: { value: "py-3.6" } +# Declare build specific Cloud project. +env_vars: { + key: "BUILD_SPECIFIC_GCLOUD_PROJECT" + value: "python-docs-samples-tests-py36" +} + env_vars: { key: "TRAMPOLINE_BUILD_FILE" value: "github/python-videointelligence/.kokoro/test-samples.sh" diff --git a/.kokoro/samples/python3.7/common.cfg b/.kokoro/samples/python3.7/common.cfg index c5274327..e315e2d1 100644 --- a/.kokoro/samples/python3.7/common.cfg +++ b/.kokoro/samples/python3.7/common.cfg @@ -13,6 +13,12 @@ env_vars: { value: "py-3.7" } +# Declare build specific Cloud project. +env_vars: { + key: "BUILD_SPECIFIC_GCLOUD_PROJECT" + value: "python-docs-samples-tests-py37" +} + env_vars: { key: "TRAMPOLINE_BUILD_FILE" value: "github/python-videointelligence/.kokoro/test-samples.sh" diff --git a/.kokoro/samples/python3.8/common.cfg b/.kokoro/samples/python3.8/common.cfg index 6c613929..6647f9c2 100644 --- a/.kokoro/samples/python3.8/common.cfg +++ b/.kokoro/samples/python3.8/common.cfg @@ -13,6 +13,12 @@ env_vars: { value: "py-3.8" } +# Declare build specific Cloud project. +env_vars: { + key: "BUILD_SPECIFIC_GCLOUD_PROJECT" + value: "python-docs-samples-tests-py38" +} + env_vars: { key: "TRAMPOLINE_BUILD_FILE" value: "github/python-videointelligence/.kokoro/test-samples.sh" diff --git a/noxfile.py b/noxfile.py index c0081b20..6ba5a347 100644 --- a/noxfile.py +++ b/noxfile.py @@ -149,7 +149,7 @@ def docs(session): """Build the docs for this library.""" session.install("-e", ".") - session.install("sphinx<=3.0.0", "alabaster", "recommonmark") + session.install("sphinx", "alabaster", "recommonmark") shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True) session.run( diff --git a/samples/labels/README.rst b/samples/labels/README.rst index ab919e7f..1dcc7688 100644 --- a/samples/labels/README.rst +++ b/samples/labels/README.rst @@ -1,3 +1,4 @@ + .. This file is automatically generated. Do not edit this file directly. Google Cloud Video Intelligence API Python Samples @@ -14,10 +15,12 @@ This directory contains samples for Google Cloud Video Intelligence API. `Google .. _Google Cloud Video Intelligence API: https://cloud.google.com/video-intelligence/docs + Setup ------------------------------------------------------------------------------- + Authentication ++++++++++++++ @@ -28,6 +31,9 @@ credentials for applications. .. _Authentication Getting Started Guide: https://cloud.google.com/docs/authentication/getting-started + + + Install Dependencies ++++++++++++++++++++ @@ -42,7 +48,7 @@ Install Dependencies .. _Python Development Environment Setup Guide: https://cloud.google.com/python/setup -#. Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+. +#. Create a virtualenv. Samples are compatible with Python 3.6+. .. code-block:: bash @@ -58,9 +64,15 @@ Install Dependencies .. _pip: https://pip.pypa.io/ .. _virtualenv: https://virtualenv.pypa.io/ + + + + + Samples ------------------------------------------------------------------------------- + labels +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ @@ -76,6 +88,7 @@ To run this sample: $ python labels.py + usage: labels.py [-h] path This application demonstrates how to detect labels from a video @@ -99,6 +112,10 @@ To run this sample: + + + + The client library ------------------------------------------------------------------------------- @@ -114,4 +131,5 @@ to `browse the source`_ and `report issues`_. https://github.com/GoogleCloudPlatform/google-cloud-python/issues -.. _Google Cloud SDK: https://cloud.google.com/sdk/ \ No newline at end of file + +.. _Google Cloud SDK: https://cloud.google.com/sdk/ diff --git a/samples/labels/noxfile.py b/samples/labels/noxfile.py new file mode 100644 index 00000000..ba55d7ce --- /dev/null +++ b/samples/labels/noxfile.py @@ -0,0 +1,224 @@ +# Copyright 2019 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. + +from __future__ import print_function + +import os +from pathlib import Path +import sys + +import nox + + +# WARNING - WARNING - WARNING - WARNING - WARNING +# WARNING - WARNING - WARNING - WARNING - WARNING +# DO NOT EDIT THIS FILE EVER! +# WARNING - WARNING - WARNING - WARNING - WARNING +# WARNING - WARNING - WARNING - WARNING - WARNING + +# Copy `noxfile_config.py` to your directory and modify it instead. + + +# `TEST_CONFIG` dict is a configuration hook that allows users to +# modify the test configurations. The values here should be in sync +# with `noxfile_config.py`. Users will copy `noxfile_config.py` into +# their directory and modify it. + +TEST_CONFIG = { + # You can opt out from the test for specific Python versions. + 'ignored_versions': ["2.7"], + + # An envvar key for determining the project id to use. Change it + # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a + # build specific Cloud project. You can also use your own string + # to use your own Cloud project. + 'gcloud_project_env': 'GOOGLE_CLOUD_PROJECT', + # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', + + # A dictionary you want to inject into your test. Don't put any + # secrets here. These values will override predefined values. + 'envs': {}, +} + + +try: + # Ensure we can import noxfile_config in the project's directory. + sys.path.append('.') + from noxfile_config import TEST_CONFIG_OVERRIDE +except ImportError as e: + print("No user noxfile_config found: detail: {}".format(e)) + TEST_CONFIG_OVERRIDE = {} + +# Update the TEST_CONFIG with the user supplied values. +TEST_CONFIG.update(TEST_CONFIG_OVERRIDE) + + +def get_pytest_env_vars(): + """Returns a dict for pytest invocation.""" + ret = {} + + # Override the GCLOUD_PROJECT and the alias. + env_key = TEST_CONFIG['gcloud_project_env'] + # This should error out if not set. + ret['GOOGLE_CLOUD_PROJECT'] = os.environ[env_key] + + # Apply user supplied envs. + ret.update(TEST_CONFIG['envs']) + return ret + + +# DO NOT EDIT - automatically generated. +# All versions used to tested samples. +ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8"] + +# Any default versions that should be ignored. +IGNORED_VERSIONS = TEST_CONFIG['ignored_versions'] + +TESTED_VERSIONS = sorted([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS]) + +INSTALL_LIBRARY_FROM_SOURCE = bool(os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False)) +# +# Style Checks +# + + +def _determine_local_import_names(start_dir): + """Determines all import names that should be considered "local". + + This is used when running the linter to insure that import order is + properly checked. + """ + file_ext_pairs = [os.path.splitext(path) for path in os.listdir(start_dir)] + return [ + basename + for basename, extension in file_ext_pairs + if extension == ".py" + or os.path.isdir(os.path.join(start_dir, basename)) + and basename not in ("__pycache__") + ] + + +# Linting with flake8. +# +# We ignore the following rules: +# E203: whitespace before ‘:’ +# E266: too many leading ‘#’ for block comment +# E501: line too long +# I202: Additional newline in a section of imports +# +# We also need to specify the rules which are ignored by default: +# ['E226', 'W504', 'E126', 'E123', 'W503', 'E24', 'E704', 'E121'] +FLAKE8_COMMON_ARGS = [ + "--show-source", + "--builtin=gettext", + "--max-complexity=20", + "--import-order-style=google", + "--exclude=.nox,.cache,env,lib,generated_pb2,*_pb2.py,*_pb2_grpc.py", + "--ignore=E121,E123,E126,E203,E226,E24,E266,E501,E704,W503,W504,I202", + "--max-line-length=88", +] + + +@nox.session +def lint(session): + session.install("flake8", "flake8-import-order") + + local_names = _determine_local_import_names(".") + args = FLAKE8_COMMON_ARGS + [ + "--application-import-names", + ",".join(local_names), + "." + ] + session.run("flake8", *args) + + +# +# Sample Tests +# + + +PYTEST_COMMON_ARGS = ["--junitxml=sponge_log.xml"] + + +def _session_tests(session, post_install=None): + """Runs py.test for a particular project.""" + if os.path.exists("requirements.txt"): + session.install("-r", "requirements.txt") + + if os.path.exists("requirements-test.txt"): + session.install("-r", "requirements-test.txt") + + if INSTALL_LIBRARY_FROM_SOURCE: + session.install("-e", _get_repo_root()) + + if post_install: + post_install(session) + + session.run( + "pytest", + *(PYTEST_COMMON_ARGS + session.posargs), + # Pytest will return 5 when no tests are collected. This can happen + # on travis where slow and flaky tests are excluded. + # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html + success_codes=[0, 5], + env=get_pytest_env_vars() + ) + + +@nox.session(python=ALL_VERSIONS) +def py(session): + """Runs py.test for a sample using the specified version of Python.""" + if session.python in TESTED_VERSIONS: + _session_tests(session) + else: + session.skip("SKIPPED: {} tests are disabled for this sample.".format( + session.python + )) + + +# +# Readmegen +# + + +def _get_repo_root(): + """ Returns the root folder of the project. """ + # Get root of this repository. Assume we don't have directories nested deeper than 10 items. + p = Path(os.getcwd()) + for i in range(10): + if p is None: + break + if Path(p / ".git").exists(): + return str(p) + p = p.parent + raise Exception("Unable to detect repository root.") + + +GENERATED_READMES = sorted([x for x in Path(".").rglob("*.rst.in")]) + + +@nox.session +@nox.parametrize("path", GENERATED_READMES) +def readmegen(session, path): + """(Re-)generates the readme for a sample.""" + session.install("jinja2", "pyyaml") + dir_ = os.path.dirname(path) + + if os.path.exists(os.path.join(dir_, "requirements.txt")): + session.install("-r", os.path.join(dir_, "requirements.txt")) + + in_file = os.path.join(dir_, "README.rst.in") + session.run( + "python", _get_repo_root() + "/scripts/readme-gen/readme_gen.py", in_file + ) diff --git a/synth.metadata b/synth.metadata index 972a2af2..bf41f1f2 100644 --- a/synth.metadata +++ b/synth.metadata @@ -3,30 +3,30 @@ { "git": { "name": ".", - "remote": "git@github.com:danoscarmike/python-videointelligence", - "sha": "7613d6b7734f439dcd1e300202d6af2fd1b88514" + "remote": "git@github.com:googleapis/python-videointelligence.git", + "sha": "4691390f7bc6829d0bfcd1ed8e110202c03f8586" } }, { "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "a7eff611370b2c17050eee9da1c168bc156e3e91", - "internalRef": "334188571" + "sha": "3738209d5e12f97b208213bd66359bf4c9d12245", + "internalRef": "334908430" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "da29da32b3a988457b49ae290112b74f14b713cc" + "sha": "0762e8ee2ec21cdfc4d82020b985a104feb0453b" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "da29da32b3a988457b49ae290112b74f14b713cc" + "sha": "0762e8ee2ec21cdfc4d82020b985a104feb0453b" } } ], From bf01df4a80c1995a7ee421f67edb8392b83479fa Mon Sep 17 00:00:00 2001 From: Dan O'Meara Date: Thu, 1 Oct 2020 23:01:17 +0000 Subject: [PATCH 33/34] chore: temporarily pins sphinx --- noxfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/noxfile.py b/noxfile.py index 6ba5a347..f207a39f 100644 --- a/noxfile.py +++ b/noxfile.py @@ -149,7 +149,7 @@ def docs(session): """Build the docs for this library.""" session.install("-e", ".") - session.install("sphinx", "alabaster", "recommonmark") + session.install("sphinx<3.0.0", "alabaster", "recommonmark") shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True) session.run( From 84ae1c5424ed14fb54d813b1b6d3ed444516bb23 Mon Sep 17 00:00:00 2001 From: Dan O'Meara Date: Thu, 8 Oct 2020 19:53:04 +0000 Subject: [PATCH 34/34] chore: fixes flaky detect_faces tests --- samples/analyze/video_detect_faces_beta_test.py | 1 - samples/analyze/video_detect_faces_gcs_beta_test.py | 1 - 2 files changed, 2 deletions(-) diff --git a/samples/analyze/video_detect_faces_beta_test.py b/samples/analyze/video_detect_faces_beta_test.py index 175f2b48..5a4ef9a9 100644 --- a/samples/analyze/video_detect_faces_beta_test.py +++ b/samples/analyze/video_detect_faces_beta_test.py @@ -30,4 +30,3 @@ def test_detect_faces(capsys): out, _ = capsys.readouterr() assert "Face detected:" in out - assert "Attributes:" in out diff --git a/samples/analyze/video_detect_faces_gcs_beta_test.py b/samples/analyze/video_detect_faces_gcs_beta_test.py index e4f666ae..3adecf60 100644 --- a/samples/analyze/video_detect_faces_gcs_beta_test.py +++ b/samples/analyze/video_detect_faces_gcs_beta_test.py @@ -30,4 +30,3 @@ def test_detect_faces(capsys): out, _ = capsys.readouterr() assert "Face detected:" in out - assert "Attributes:" in out