Skip to content

Commit

Permalink
samples: updates face recognition to v1 (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Schmidt committed Apr 5, 2021
1 parent d718bde commit cfce7a2
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 30 deletions.
38 changes: 20 additions & 18 deletions videointelligence/samples/analyze/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,25 @@

TEST_CONFIG = {
# You can opt out from the test for specific Python versions.
'ignored_versions': ["2.7"],

"ignored_versions": ["2.7"],
# Old samples are opted out of enforcing Python type hints
# All new samples should feature them
'enforce_type_hints': False,

"enforce_type_hints": False,
# 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": "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': {},
"envs": {},
}


try:
# Ensure we can import noxfile_config in the project's directory.
sys.path.append('.')
sys.path.append(".")
from noxfile_config import TEST_CONFIG_OVERRIDE
except ImportError as e:
print("No user noxfile_config found: detail: {}".format(e))
Expand All @@ -74,12 +71,12 @@ def get_pytest_env_vars() -> Dict[str, str]:
ret = {}

# Override the GCLOUD_PROJECT and the alias.
env_key = TEST_CONFIG['gcloud_project_env']
env_key = TEST_CONFIG["gcloud_project_env"]
# This should error out if not set.
ret['GOOGLE_CLOUD_PROJECT'] = os.environ[env_key]
ret["GOOGLE_CLOUD_PROJECT"] = os.environ[env_key]

# Apply user supplied envs.
ret.update(TEST_CONFIG['envs'])
ret.update(TEST_CONFIG["envs"])
return ret


Expand All @@ -88,7 +85,7 @@ def get_pytest_env_vars() -> Dict[str, str]:
ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8", "3.9"]

# Any default versions that should be ignored.
IGNORED_VERSIONS = TEST_CONFIG['ignored_versions']
IGNORED_VERSIONS = TEST_CONFIG["ignored_versions"]

TESTED_VERSIONS = sorted([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS])

Expand Down Expand Up @@ -137,7 +134,7 @@ def _determine_local_import_names(start_dir: str) -> List[str]:

@nox.session
def lint(session: nox.sessions.Session) -> None:
if not TEST_CONFIG['enforce_type_hints']:
if not TEST_CONFIG["enforce_type_hints"]:
session.install("flake8", "flake8-import-order")
else:
session.install("flake8", "flake8-import-order", "flake8-annotations")
Expand All @@ -146,9 +143,11 @@ def lint(session: nox.sessions.Session) -> None:
args = FLAKE8_COMMON_ARGS + [
"--application-import-names",
",".join(local_names),
"."
".",
]
session.run("flake8", *args)


#
# Black
#
Expand All @@ -161,6 +160,7 @@ def blacken(session: nox.sessions.Session) -> None:

session.run("black", *python_files)


#
# Sample Tests
#
Expand All @@ -169,7 +169,9 @@ def blacken(session: nox.sessions.Session) -> None:
PYTEST_COMMON_ARGS = ["--junitxml=sponge_log.xml"]


def _session_tests(session: nox.sessions.Session, post_install: Callable = None) -> None:
def _session_tests(
session: nox.sessions.Session, post_install: Callable = None
) -> None:
"""Runs py.test for a particular project."""
if os.path.exists("requirements.txt"):
session.install("-r", "requirements.txt")
Expand Down Expand Up @@ -200,9 +202,9 @@ def py(session: nox.sessions.Session) -> None:
if session.python in TESTED_VERSIONS:
_session_tests(session)
else:
session.skip("SKIPPED: {} tests are disabled for this sample.".format(
session.python
))
session.skip(
"SKIPPED: {} tests are disabled for this sample.".format(session.python)
)


#
Expand Down
2 changes: 1 addition & 1 deletion videointelligence/samples/analyze/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
google-cloud-videointelligence==2.0.0
google-cloud-videointelligence==2.1.0
google-cloud-storage==1.37.0
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 Google LLC
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -12,10 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# [START video_detect_faces_beta]
# [START video_detect_faces]
import io

from google.cloud import videointelligence_v1p3beta1 as videointelligence
from google.cloud import videointelligence_v1 as videointelligence


def detect_faces(local_file_path="path/to/your/video-file.mp4"):
Expand Down Expand Up @@ -82,4 +82,4 @@ def detect_faces(local_file_path="path/to/your/video-file.mp4"):
)


# [END video_detect_faces_beta]
# [END video_detect_faces]
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# [START video_detect_faces_gcs_beta]
from google.cloud import videointelligence_v1p3beta1 as videointelligence
# [START video_detect_faces_gcs]
from google.cloud import videointelligence_v1 as videointelligence


def detect_faces(gcs_uri="gs://YOUR_BUCKET_ID/path/to/your/video.mp4"):
Expand Down Expand Up @@ -77,4 +77,4 @@ def detect_faces(gcs_uri="gs://YOUR_BUCKET_ID/path/to/your/video.mp4"):
)


# [END video_detect_faces_gcs_beta]
# [END video_detect_faces_gcs]
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import pytest

import video_detect_faces_gcs_beta
import video_detect_faces_gcs

RESOURCES = os.path.join(os.path.dirname(__file__), "resources")

Expand All @@ -25,7 +25,7 @@
def test_detect_faces(capsys):
input_uri = "gs://cloud-samples-data/video/googlework_short.mp4"

video_detect_faces_gcs_beta.detect_faces(gcs_uri=input_uri)
video_detect_faces_gcs.detect_faces(gcs_uri=input_uri)

out, _ = capsys.readouterr()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import pytest

import video_detect_faces_beta
import video_detect_faces

RESOURCES = os.path.join(os.path.dirname(__file__), "resources")

Expand All @@ -25,7 +25,7 @@
def test_detect_faces(capsys):
local_file_path = os.path.join(RESOURCES, "googlework_short.mp4")

video_detect_faces_beta.detect_faces(local_file_path=local_file_path)
video_detect_faces.detect_faces(local_file_path=local_file_path)

out, _ = capsys.readouterr()

Expand Down

0 comments on commit cfce7a2

Please sign in to comment.