coufon commented on a change in pull request #4791:  [AIRFLOW-3908] Add more 
Google Cloud Vision operators
URL: https://github.com/apache/airflow/pull/4791#discussion_r261420342
 
 

 ##########
 File path: airflow/contrib/operators/gcp_vision_operator.py
 ##########
 @@ -671,3 +672,284 @@ def execute(self, context):
             timeout=self.timeout,
             metadata=self.metadata,
         )
+
+
+class CloudVisionAnnotateImageOperator(BaseOperator):
+    """
+    Run image detection and annotation for an image.
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the 
guide:
+        :ref:`howto/operator:CloudVisionAnnotateImageOperator`
+
+    :param request: (Required) Individual file annotation requests.
+        If a dict is provided, it must be of the same form as the protobuf
+        message class:`google.cloud.vision_v1.types.AnnotateImageRequest`
+    :type request: dict or google.cloud.vision_v1.types.AnnotateImageRequest
+    :param retry: (Optional) A retry object used to retry requests. If `None` 
is
+        specified, requests will not be retried.
+    :type retry: google.api_core.retry.Retry
+    :param timeout: (Optional) The amount of time, in seconds, to wait for the 
request to
+        complete. Note that if retry is specified, the timeout applies to each 
individual
+        attempt.
+    :type timeout: float
+    :param gcp_conn_id: (Optional) The connection ID used to connect to Google 
Cloud Platform.
+    :type gcp_conn_id: str
+    """
+
+    # [START vision_annotate_image_template_fields]
+    template_fields = ('request', 'gcp_conn_id')
+    # [END vision_annotate_image_template_fields]
+
+    @apply_defaults
+    def __init__(
+        self, request, retry=None, timeout=None, 
gcp_conn_id='google_cloud_default', *args, **kwargs
+    ):
+        super(CloudVisionAnnotateImageOperator, self).__init__(*args, **kwargs)
+        self.request = request
+        self.retry = retry
+        self.timeout = timeout
+        self.gcp_conn_id = gcp_conn_id
+
+    def execute(self, context):
+        hook = CloudVisionHook(gcp_conn_id=self.gcp_conn_id)
+        return hook.annotate_image(request=self.request, retry=self.retry, 
timeout=self.timeout)
+
+
+class CloudVisionReferenceImageCreateOperator(BaseOperator):
+    """
+    Creates and returns a new ReferenceImage ID resource.
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the 
guide:
+        :ref:`howto/operator:CloudVisionReferenceImageCreateOperator`
+
+    :param location: (Required) The region where the Product is located. Valid 
regions (as of 2019-02-05) are:
+        us-east1, us-west1, europe-west1, asia-east1
+    :type location: str
+    :param reference_image: (Required) The reference image to create. If an 
image ID is specified, it is
+        ignored.
+        If a dict is provided, it must be of the same form as the protobuf 
message
+        :class:`google.cloud.vision_v1.types.ReferenceImage`
+    :type reference_image: dict or google.cloud.vision_v1.types.ReferenceImage
+    :param reference_image_id: (Optional) A user-supplied resource id for the 
ReferenceImage to be added.
+        If set, the server will attempt to use this value as the resource id. 
If it is already in use, an
+        error is returned with code ALREADY_EXISTS. Must be at most 128 
characters long. It cannot contain
+        the character `/`.
+    :type reference_image_id: str
+    :param product_id: (Optional) The resource id of this Product.
+    :type product_id: str
+    :param project_id: (Optional) The project in which the Product is located. 
If set to None or
+        missing, the default project_id from the GCP connection is used.
+    :type project_id: str
+    :param retry: (Optional) A retry object used to retry requests. If `None` 
is
+        specified, requests will not be retried.
+    :type retry: google.api_core.retry.Retry
+    :param timeout: (Optional) The amount of time, in seconds, to wait for the 
request to
+        complete. Note that if retry is specified, the timeout applies to each 
individual
+        attempt.
+    :type timeout: float
+    :param metadata: (Optional) Additional metadata that is provided to the 
method.
+    :type metadata: sequence[tuple[str, str]]
+    :param gcp_conn_id: (Optional) The connection ID used to connect to Google 
Cloud Platform.
+    :type gcp_conn_id: str
+    """
+
+    # [START vision_reference_image_create_template_fields]
+    template_fields = ('location', 'product_id', 'reference_image_id', 
'project_id', 'gcp_conn_id')
+    # [END vision_reference_image_create_template_fields]
+
+    @apply_defaults
+    def __init__(
+        self,
+        location,
+        reference_image,
+        product_id,
+        reference_image_id=None,
+        project_id=None,
+        retry=None,
+        timeout=None,
+        metadata=None,
+        gcp_conn_id='google_cloud_default',
+        *args,
+        **kwargs
+    ):
+        super(CloudVisionReferenceImageCreateOperator, self).__init__(*args, 
**kwargs)
+        self.location = location
+        self.product_id = product_id
+        self.reference_image = reference_image
+        self.reference_image_id = reference_image_id
+        self.project_id = project_id
+        self.retry = retry
+        self.timeout = timeout
+        self.metadata = metadata
+        self.gcp_conn_id = gcp_conn_id
+
+    def execute(self, context):
+        try:
+            hook = CloudVisionHook(gcp_conn_id=self.gcp_conn_id)
+            return hook.create_reference_image(
+                location=self.location,
+                product_id=self.product_id,
+                reference_image=self.reference_image,
+                reference_image_id=self.reference_image_id,
+                project_id=self.project_id,
+                retry=self.retry,
+                timeout=self.timeout,
+                metadata=self.metadata,
+            )
+        except AlreadyExists:
+            self.log.info(
+                'ReferenceImage with id %s already exists. Exiting from the 
create operation.',
+                self.product_id,
+            )
+            return self.reference_image_id
+
+
+class CloudVisionAddProductToProductSetOperator(BaseOperator):
+    """
+    Adds a Product to the specified ProductSet. If the Product is already 
present, no change is made.
+
+    One Product can be added to at most 100 ProductSets.
+
+    Possible errors:
+
+    - Returns `NOT_FOUND` if the Product or the ProductSet doesn’t exist.
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the 
guide:
+        :ref:`howto/operator:CloudVisionAddProductToProductSetOperator`
+
+    :param product_set_id: (Required) The resource id for the ProductSet to 
modify.
+    :type product_set_id: str
+    :param product_id: (Required) The resource id of this Product.
+    :type product_id: str
+    :param location: (Required) The region where the ProductSet is located. 
Valid regions (as of 2019-02-05)
+        are: us-east1, us-west1, europe-west1, asia-east1
+    :type: str
+    :param project_id: (Optional) The project in which the Product is located. 
If set to None or
+        missing, the default project_id from the GCP connection is used.
+    :type project_id: str
+    :param retry: (Optional) A retry object used to retry requests. If `None` 
is
+        specified, requests will not be retried.
+    :type retry: google.api_core.retry.Retry
+    :param timeout: (Optional) The amount of time, in seconds, to wait for the 
request to
+        complete. Note that if retry is specified, the timeout applies to each 
individual
+        attempt.
+    :type timeout: float
+    :param metadata: (Optional) Additional metadata that is provided to the 
method.
+    :type metadata: sequence[tuple[str, str]]
+    :param gcp_conn_id: (Optional) The connection ID used to connect to Google 
Cloud Platform.
+    :type gcp_conn_id: str
+    """
+
+    # [START vision_add_product_to_product_set_template_fields]
+    template_fields = ('location', 'product_set_id', 'product_id', 
'project_id', 'gcp_conn_id')
+    # [END vision_add_product_to_product_set_template_fields]
 
 Review comment:
   nit: maybe add a blank line

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to