mwalenia commented on a change in pull request #11331:
URL: https://github.com/apache/beam/pull/11331#discussion_r422993259



##########
File path: 
sdks/java/extensions/ml/src/main/java/org/apache/beam/sdk/extensions/ml/CloudVision.java
##########
@@ -0,0 +1,238 @@
+/*
+ * 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.
+ */
+package org.apache.beam.sdk.extensions.ml;
+
+import com.google.cloud.vision.v1.AnnotateImageRequest;
+import com.google.cloud.vision.v1.Feature;
+import com.google.cloud.vision.v1.Image;
+import com.google.cloud.vision.v1.ImageContext;
+import com.google.cloud.vision.v1.ImageSource;
+import com.google.protobuf.ByteString;
+import java.util.List;
+import java.util.Map;
+import org.apache.beam.sdk.values.KV;
+import org.apache.beam.sdk.values.PCollectionView;
+
+/**
+ * Factory class for implementations of {@link AnnotateImages}.
+ *
+ * <p>Example usage:
+ *
+ * <pre>
+ * pipeline
+ *  .apply(Create.of(IMAGE_URI))
+ *  .apply(CloudVision.annotateImagesFromGcsUri(sideInputWithContext,
+ *         features, 1));
+ * </pre>
+ */
+public class CloudVision {
+
+  /**
+   * Creates a {@link org.apache.beam.sdk.transforms.PTransform} that 
annotates images from their
+   * GCS addresses.
+   *
+   * @param contextSideInput optional side input with contexts for select 
images.
+   * @param features annotation features that should be passed to the API
+   * @param batchSize request batch size to be sent to API. Max 5.
+   * @return the PTransform.
+   */
+  public static AnnotateImagesFromGcsUri annotateImagesFromGcsUri(
+      PCollectionView<Map<String, ImageContext>> contextSideInput,
+      List<Feature> features,
+      long batchSize) {
+    return new AnnotateImagesFromGcsUri(contextSideInput, features, batchSize);
+  }
+
+  /**
+   * Creates a {@link org.apache.beam.sdk.transforms.PTransform} that 
annotates images from their
+   * contents encoded in {@link ByteString}s.
+   *
+   * @param contextSideInput optional side input with contexts for select 
images.
+   * @param features annotation features that should be passed to the API
+   * @param batchSize request batch size to be sent to API. Max 5.
+   * @return the PTransform.
+   */
+  public static AnnotateImagesFromBytes annotateImagesFromBytes(
+      PCollectionView<Map<ByteString, ImageContext>> contextSideInput,
+      List<Feature> features,
+      long batchSize) {
+    return new AnnotateImagesFromBytes(contextSideInput, features, batchSize);
+  }
+
+  /**
+   * Creates a {@link org.apache.beam.sdk.transforms.PTransform} that 
annotates images from KVs of
+   * their GCS addresses in Strings and {@link ImageContext} for each image.
+   *
+   * @param features annotation features that should be passed to the API
+   * @param batchSize request batch size to be sent to API. Max 5.
+   * @return the PTransform.
+   */
+  public static AnnotateImagesFromBytesWithContext 
annotateImagesFromBytesWithContext(
+      List<Feature> features, long batchSize) {
+    return new AnnotateImagesFromBytesWithContext(features, batchSize);
+  }
+
+  /**
+   * Creates a {@link org.apache.beam.sdk.transforms.PTransform} that 
annotates images from KVs of
+   * their String-encoded contents and {@link ImageContext} for each image.
+   *
+   * @param features annotation features that should be passed to the API
+   * @param batchSize request batch size to be sent to API. Max 5.
+   * @return the PTransform.
+   */
+  public static AnnotateImagesFromGcsUriWithContext 
annotateImagesFromGcsUriWithContext(
+      List<Feature> features, long batchSize) {
+    return new AnnotateImagesFromGcsUriWithContext(features, batchSize);
+  }
+
+  /**
+   * Implementation of {@link AnnotateImages} that accepts {@link String} 
(image URI on GCS) with

Review comment:
       Good idea, thanks

##########
File path: settings.gradle
##########
@@ -167,3 +167,6 @@ include "beam-test-infra-metrics"
 project(":beam-test-infra-metrics").dir = file(".test-infra/metrics")
 include "beam-test-tools"
 project(":beam-test-tools").dir = file(".test-infra/tools")
+include 'sdks:java:extensions:ml'
+findProject(':sdks:java:extensions:ml')?.name = 'ml'

Review comment:
       That's an oversight on my part, I'll delete this.
   The inclusion was already added in earlier PRs, the rebase will make this 
change unnecessary.




----------------------------------------------------------------
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:
[email protected]


Reply via email to