Skip to content

Commit 5132d60

Browse files
dizcologyJon Wayne Parrott
authored andcommitted
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
1 parent 5739425 commit 5132d60

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

samples/labels/labels.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,36 +30,28 @@
3030
# [START full_tutorial]
3131
# [START imports]
3232
import argparse
33-
import sys
34-
import time
3533

36-
from google.cloud import videointelligence_v1beta2
37-
from google.cloud.videointelligence_v1beta2 import enums
34+
from google.cloud import videointelligence
3835
# [END imports]
3936

4037

4138
def analyze_labels(path):
4239
""" Detects labels given a GCS path. """
4340
# [START construct_request]
44-
video_client = videointelligence_v1beta2.VideoIntelligenceServiceClient()
45-
features = [enums.Feature.LABEL_DETECTION]
46-
operation = video_client.annotate_video(path, features)
41+
video_client = videointelligence.VideoIntelligenceServiceClient()
42+
features = [videointelligence.enums.Feature.LABEL_DETECTION]
43+
operation = video_client.annotate_video(path, features=features)
4744
# [END construct_request]
4845
print('\nProcessing video for label annotations:')
4946

5047
# [START check_operation]
51-
while not operation.done():
52-
sys.stdout.write('.')
53-
sys.stdout.flush()
54-
time.sleep(20)
55-
48+
result = operation.result(timeout=90)
5649
print('\nFinished processing.')
5750
# [END check_operation]
5851

5952
# [START parse_response]
60-
results = operation.result().annotation_results[0]
61-
62-
for i, segment_label in enumerate(results.segment_label_annotations):
53+
segment_labels = result.annotation_results[0].segment_label_annotations
54+
for i, segment_label in enumerate(segment_labels):
6355
print('Video label description: {}'.format(
6456
segment_label.entity.description))
6557
for category_entity in segment_label.category_entities:

samples/labels/labels_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
# limitations under the License.
1616

1717
import os
18+
1819
import pytest
20+
1921
import labels
2022

2123

samples/labels/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
google-cloud-videointelligence==0.28.0
1+
google-cloud-videointelligence==1.0.0

0 commit comments

Comments
 (0)