[ 
https://issues.apache.org/jira/browse/BEAM-9146?focusedWorklogId=383075&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-383075
 ]

ASF GitHub Bot logged work on BEAM-9146:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 06/Feb/20 19:15
            Start Date: 06/Feb/20 19:15
    Worklog Time Spent: 10m 
      Work Description: aaltay commented on pull request #10764: [BEAM-9146] 
Integrate GCP Video Intelligence functionality for Python SDK
URL: https://github.com/apache/beam/pull/10764#discussion_r376029674
 
 

 ##########
 File path: sdks/python/apache_beam/ml/gcp/video_intelligence.py
 ##########
 @@ -0,0 +1,131 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+#
+
+"""
+A connector for sending API requests to the GCP Video Intelligence API.
+"""
+from __future__ import absolute_import
+
+from cachetools.func import ttl_cache
+from future.utils import binary_type, text_type
+from typing import Union
+
+from apache_beam import typehints
+from apache_beam.metrics import Metrics
+from apache_beam.transforms import DoFn, ParDo, PTransform
+
+try:
+  from google.cloud import videointelligence
+except ImportError:
+  raise ImportError(
+      'Google Cloud Video Intelligence not supported for this execution 
environment '
+      '(could not import google.cloud.videointelligence).')
+
+__all__ = ['AnnotateVideo']
+
+
+@ttl_cache(maxsize=128, ttl=3600)
+def get_videointelligence_client():
+  """Returns a Cloud Video Intelligence client."""
+  _client = videointelligence.VideoIntelligenceServiceClient()
+  return _client
+
+
+class AnnotateVideo(PTransform):
+  """A ``PTransform`` for annotating video using the GCP Video Intelligence API
+  ref: https://cloud.google.com/video-intelligence/docs
+  """
+  def __init__(
+      self,
+      features,
+      video_context=None,
+      location_id=None,
+      metadata=None,
+      timeout=120):
+    """
+      Args:
+        features: (List[``videointelligence_v1.enums.Feature``]) Required.
+          the Video Intelligence API features to detect
+        video_context: (dict, ``videointelligence_v1.types.VideoContext``)
+          Optional.
+          Additional video context and/or feature-specific parameters.
+        location_id: (str) Optional.
+          Cloud region where annotation should take place.
+          If no region is specified, a region will be determined
+          based on video file location.
+        metadata: (Sequence[Tuple[str, str]]) Optional.
+          Additional metadata that is provided to the method.
+        timeout: (int) Optional.
+          The time in seconds to wait for the response from the Video 
Intelligence API
+    """
+    super(AnnotateVideo, self).__init__()
+    self.features = features
+    self.video_context = video_context
+    self.location_id = location_id
+    self.metadata = metadata
+    self.timeout = timeout
+
+  def expand(self, pvalue):
+    return pvalue | ParDo(
+        self._VideoAnnotateFn(
+            features=self.features,
+            video_context=self.video_context,
+            location_id=self.location_id,
+            metadata=self.metadata,
+            timeout=self.timeout))
+
+  @typehints.with_input_types(Union[text_type, binary_type])
+  class _VideoAnnotateFn(DoFn):
+    """ A DoFn that sends each input element to the GCP Video Intelligence API
+        service and outputs an element with the return result of the API
+        (``google.cloud.videointelligence_v1.types.AnnotateVideoResponse``).
+     """
+    def __init__(self, features, video_context, location_id, metadata, 
timeout):
 
 Review comment:
   We can default the timeout to 120 here. If you think that is a reasonable 
default.
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 383075)
    Time Spent: 4.5h  (was: 4h 20m)

> [Python] PTransform that integrates Video Intelligence functionality
> --------------------------------------------------------------------
>
>                 Key: BEAM-9146
>                 URL: https://issues.apache.org/jira/browse/BEAM-9146
>             Project: Beam
>          Issue Type: Sub-task
>          Components: io-py-gcp
>            Reporter: Kamil Wasilewski
>            Assignee: Kamil Wasilewski
>            Priority: Major
>          Time Spent: 4.5h
>  Remaining Estimate: 0h
>
> The goal is to create a PTransform that integrates Google Cloud Video 
> Intelligence functionality [1].
> The transform should be able to take both video GCS location or video data 
> bytes as an input.
> [1] https://cloud.google.com/video-intelligence/



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to