Skip to content
This repository has been archived by the owner on Nov 29, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
docs: add samples from video/cloud-client/labels (#49)
* Adds tutorials using Cloud Client [(#930)](GoogleCloudPlatform/python-docs-samples#930)

* Adds tutorials.

* Removes unused enumerate

* Adds new examples, replaces markdown with restructured text [(#945)](GoogleCloudPlatform/python-docs-samples#945)

* Adds new examples, replaces markdown with restructured text

* Address review feedback

* Use videos from pubilc bucket, update to new client library.

* Style nit

* Updates requirements [(#952)](GoogleCloudPlatform/python-docs-samples#952)

* Fix README rst links [(#962)](GoogleCloudPlatform/python-docs-samples#962)

* Fix README rst links

* Update all READMEs

* Auto-update dependencies. [(#1093)](GoogleCloudPlatform/python-docs-samples#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

* Update all generated readme auth instructions [(#1121)](GoogleCloudPlatform/python-docs-samples#1121)

Change-Id: I03b5eaef8b17ac3dc3c0339fd2c7447bd3e11bd2

* Auto-update dependencies. [(#1123)](GoogleCloudPlatform/python-docs-samples#1123)

* Video v1beta2 [(#1088)](GoogleCloudPlatform/python-docs-samples#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

* Added Link to Python Setup Guide [(#1158)](GoogleCloudPlatform/python-docs-samples#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

* Tweak doc/help strings for sample tools  [(#1160)](GoogleCloudPlatform/python-docs-samples#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

* Auto-update dependencies. [(#1186)](GoogleCloudPlatform/python-docs-samples#1186)

* update samples to v1 [(#1221)](GoogleCloudPlatform/python-docs-samples#1221)

* update samples to v1

* replace while loop with operation.result(timeout)

* addressing review comments

* flake

* flake

* Added "Open in Cloud Shell" buttons to README files [(#1254)](GoogleCloudPlatform/python-docs-samples#1254)

* Auto-update dependencies. [(#1377)](GoogleCloudPlatform/python-docs-samples#1377)

* Auto-update dependencies.

* Update requirements.txt

* Auto-update dependencies.

* Regenerate the README files and fix the Open in Cloud Shell link for some samples [(#1441)](GoogleCloudPlatform/python-docs-samples#1441)

* Update READMEs to fix numbering and add git clone [(#1464)](GoogleCloudPlatform/python-docs-samples#1464)

* Video Intelligence region tag update [(#1639)](GoogleCloudPlatform/python-docs-samples#1639)

* Auto-update dependencies. [(#1658)](GoogleCloudPlatform/python-docs-samples#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.

* Use explicit URIs for Video Intelligence sample tests [(#1743)](GoogleCloudPlatform/python-docs-samples#1743)

* Auto-update dependencies. [(#1846)](GoogleCloudPlatform/python-docs-samples#1846)

ACK, merging.

* Auto-update dependencies. [(#1980)](GoogleCloudPlatform/python-docs-samples#1980)

* Auto-update dependencies.

* Update requirements.txt

* Update requirements.txt

* replace demomaker with cloud-samples-data/video for video intelligenc… [(#2162)](GoogleCloudPlatform/python-docs-samples#2162)

* replace demomaker with cloud-samples-data/video for video intelligence samples

* flake

* Adds updates for samples profiler ... vision [(#2439)](GoogleCloudPlatform/python-docs-samples#2439)

* Auto-update dependencies. [(#2005)](GoogleCloudPlatform/python-docs-samples#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 <dmahugh@gmail.com>

* chore(deps): update dependency google-cloud-videointelligence to v1.14.0 [(#3169)](GoogleCloudPlatform/python-docs-samples#3169)

* Simplify noxfile setup. [(#2806)](GoogleCloudPlatform/python-docs-samples#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 <bot@renovateapp.com>

* fix: changes positional to named pararameters in Video samples [(#4017)](GoogleCloudPlatform/python-docs-samples#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)
```

* Update dependency google-cloud-videointelligence to v1.15.0 [(#4041)](GoogleCloudPlatform/python-docs-samples#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

<details>
<summary>googleapis/python-videointelligence</summary>

### [`v1.15.0`](https://togithub.com/googleapis/python-videointelligence/blob/master/CHANGELOG.md#&#8203;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 ([#&#8203;31](https://www.github.com/googleapis/python-videointelligence/issues/31)) ([586f920](https://www.github.com/googleapis/python-videointelligence/commit/586f920a1932e1a813adfed500502fba0ff5edb7)), closes [#&#8203;517](https://www.github.com/googleapis/python-videointelligence/issues/517) [#&#8203;538](https://www.github.com/googleapis/python-videointelligence/issues/538) [#&#8203;565](https://www.github.com/googleapis/python-videointelligence/issues/565) [#&#8203;576](https://www.github.com/googleapis/python-videointelligence/issues/576) [#&#8203;506](https://www.github.com/googleapis/python-videointelligence/issues/506) [#&#8203;586](https://www.github.com/googleapis/python-videointelligence/issues/586) [#&#8203;585](https://www.github.com/googleapis/python-videointelligence/issues/585)

</details>

---

### 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.

---

 - [ ] <!-- rebase-check -->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).

* chore(deps): update dependency pytest to v5.4.3 [(#4279)](GoogleCloudPlatform/python-docs-samples#4279)

* chore(deps): update dependency pytest to v5.4.3

* specify pytest for python 2 in appengine

Co-authored-by: Leah Cole <coleleah@google.com>

* Update dependency pytest to v6 [(#4390)](GoogleCloudPlatform/python-docs-samples#4390)

* chore: adds samples templates

* chore: temporarily pins sphinx

* chore: fixes flaky detect_faces tests

Co-authored-by: Gus Class <gguuss@gmail.com>
Co-authored-by: Bill Prin <waprin@gmail.com>
Co-authored-by: DPE bot <dpebot@google.com>
Co-authored-by: Jon Wayne Parrott <jonwayne@google.com>
Co-authored-by: Yu-Han Liu <dizcology@hotmail.com>
Co-authored-by: michaelawyu <chenyumic@google.com>
Co-authored-by: Perry Stoll <pstoll@users.noreply.github.com>
Co-authored-by: Frank Natividad <frankyn@users.noreply.github.com>
Co-authored-by: michaelawyu <michael.a.w.yu@hotmail.com>
Co-authored-by: Alix Hamilton <ajhamilton@google.com>
Co-authored-by: Yu-Han Liu <yuhanliu@google.com>
Co-authored-by: Kurtis Van Gent <31518063+kurtisvg@users.noreply.github.com>
Co-authored-by: Doug Mahugh <dmahugh@gmail.com>
Co-authored-by: WhiteSource Renovate <bot@renovateapp.com>
Co-authored-by: Eric Schmidt <erschmid@google.com>
Co-authored-by: Leah Cole <coleleah@google.com>
Co-authored-by: gcf-merge-on-green[bot] <60162190+gcf-merge-on-green[bot]@users.noreply.github.com>
  • Loading branch information
18 people committed Oct 13, 2020
1 parent ee1ada6 commit 07806d3
Show file tree
Hide file tree
Showing 12 changed files with 518 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .kokoro/samples/python3.6/common.cfg
Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions .kokoro/samples/python3.7/common.cfg
Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions .kokoro/samples/python3.8/common.cfg
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion noxfile.py
Expand Up @@ -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(
Expand Down
135 changes: 135 additions & 0 deletions samples/labels/README.rst
@@ -0,0 +1,135 @@

.. This file is automatically generated. Do not edit this file directly.
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.




.. _Google Cloud Video Intelligence API: https://cloud.google.com/video-intelligence/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 3.6+.

.. 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
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

.. 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:

.. code-block:: bash
$ python labels.py
usage: labels.py [-h] path
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
-------------------------------------------------------------------------------

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/
22 changes: 22 additions & 0 deletions samples/labels/README.rst.in
@@ -0,0 +1,22 @@
# 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

folder: video/cloud-client/labels
84 changes: 84 additions & 0 deletions samples/labels/labels.py
@@ -0,0 +1,84 @@
#!/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 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
"""

# [START video_label_tutorial]
# [START video_label_tutorial_imports]
import argparse

from google.cloud import videointelligence
# [END video_label_tutorial_imports]


def analyze_labels(path):
""" Detects labels given a GCS path. """
# [START video_label_tutorial_construct_request]
video_client = videointelligence.VideoIntelligenceServiceClient()
features = [videointelligence.enums.Feature.LABEL_DETECTION]
operation = video_client.annotate_video(input_uri=path, features=features)
# [END video_label_tutorial_construct_request]
print('\nProcessing video for label annotations:')

# [START video_label_tutorial_check_operation]
result = operation.result(timeout=90)
print('\nFinished processing.')
# [END video_label_tutorial_check_operation]

# [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(
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 video_label_tutorial_parse_response]


if __name__ == '__main__':
# [START video_label_tutorial_run_application]
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 video_label_tutorial_run_application]
# [END video_label_tutorial]
26 changes: 26 additions & 0 deletions samples/labels/labels_test.py
@@ -0,0 +1,26 @@
#!/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 pytest

import labels


@pytest.mark.slow
def test_feline_video_labels(capsys):
labels.analyze_labels('gs://cloud-samples-data/video/cat.mp4')
out, _ = capsys.readouterr()
assert 'Video label description: cat' in out

0 comments on commit 07806d3

Please sign in to comment.