Skip to content

Commit

Permalink
update samples to v1 [(#1221)](GoogleCloudPlatform/python-docs-sample…
Browse files Browse the repository at this point in the history
…s#1221)

* update samples to v1

* replace while loop with operation.result(timeout)

* addressing review comments

* flake

* flake
  • Loading branch information
dizcology authored and Jon Wayne Parrott committed Nov 29, 2017
1 parent 5739425 commit 5132d60
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
22 changes: 7 additions & 15 deletions samples/labels/labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions samples/labels/labels_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
# limitations under the License.

import os

import pytest

import labels


Expand Down
2 changes: 1 addition & 1 deletion samples/labels/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
google-cloud-videointelligence==0.28.0
google-cloud-videointelligence==1.0.0

0 comments on commit 5132d60

Please sign in to comment.