Skip to content

Commit

Permalink
samples: update shared config (#2443)
Browse files Browse the repository at this point in the history
* update shared config

* Update to 1.0.13

* lint

* Fix linting

* lint

* fix imports

Co-authored-by: Les Vogel <lesv@users.noreply.github.com>
  • Loading branch information
2 people authored and Shabirmean committed Nov 18, 2022
1 parent 9ac9c23 commit 64341f0
Show file tree
Hide file tree
Showing 70 changed files with 32 additions and 128 deletions.
21 changes: 10 additions & 11 deletions automl/snippets/src/main/java/com/example/automl/BatchPredict.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.google.cloud.automl.v1.ModelName;
import com.google.cloud.automl.v1.OperationMetadata;
import com.google.cloud.automl.v1.PredictionServiceClient;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

Expand All @@ -43,7 +42,7 @@ static void batchPredict() throws IOException, ExecutionException, InterruptedEx
}

static void batchPredict(String projectId, String modelId, String inputUri, String outputUri)
throws IOException, ExecutionException, InterruptedException {
throws IOException, ExecutionException, InterruptedException {
// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests. After completing all of your requests, call
// the "close" method on the client to safely clean up any remaining background resources.
Expand All @@ -52,20 +51,20 @@ static void batchPredict(String projectId, String modelId, String inputUri, Stri
ModelName name = ModelName.of(projectId, "us-central1", modelId);
GcsSource gcsSource = GcsSource.newBuilder().addInputUris(inputUri).build();
BatchPredictInputConfig inputConfig =
BatchPredictInputConfig.newBuilder().setGcsSource(gcsSource).build();
BatchPredictInputConfig.newBuilder().setGcsSource(gcsSource).build();
GcsDestination gcsDestination =
GcsDestination.newBuilder().setOutputUriPrefix(outputUri).build();
GcsDestination.newBuilder().setOutputUriPrefix(outputUri).build();
BatchPredictOutputConfig outputConfig =
BatchPredictOutputConfig.newBuilder().setGcsDestination(gcsDestination).build();
BatchPredictOutputConfig.newBuilder().setGcsDestination(gcsDestination).build();
BatchPredictRequest request =
BatchPredictRequest.newBuilder()
.setName(name.toString())
.setInputConfig(inputConfig)
.setOutputConfig(outputConfig)
.build();
BatchPredictRequest.newBuilder()
.setName(name.toString())
.setInputConfig(inputConfig)
.setOutputConfig(outputConfig)
.build();

OperationFuture<BatchPredictResult, OperationMetadata> future =
client.batchPredictAsync(request);
client.batchPredictAsync(request);

System.out.println("Waiting for operation to complete...");
BatchPredictResult response = future.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.google.cloud.automl.v1.AutoMlClient;
import com.google.cloud.automl.v1.DatasetName;
import com.google.protobuf.Empty;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.google.cloud.automl.v1.AutoMlClient;
import com.google.cloud.automl.v1.ModelName;
import com.google.protobuf.Empty;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.google.cloud.automl.v1.ModelName;
import com.google.cloud.automl.v1.OperationMetadata;
import com.google.protobuf.Empty;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.google.cloud.automl.v1.GcsDestination;
import com.google.cloud.automl.v1.OutputConfig;
import com.google.protobuf.Empty;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.google.cloud.automl.v1.AutoMlClient;
import com.google.cloud.automl.v1.Dataset;
import com.google.cloud.automl.v1.DatasetName;

import java.io.IOException;

class GetDataset {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.google.cloud.automl.v1.AutoMlClient;
import com.google.cloud.automl.v1.Model;
import com.google.cloud.automl.v1.ModelName;

import java.io.IOException;

class GetModel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.google.cloud.automl.v1.AutoMlClient;
import com.google.cloud.automl.v1.ModelEvaluation;
import com.google.cloud.automl.v1.ModelEvaluationName;

import java.io.IOException;

class GetModelEvaluation {
Expand All @@ -41,14 +40,14 @@ static void getModelEvaluation() throws IOException {

// Get a model evaluation
static void getModelEvaluation(String projectId, String modelId, String modelEvaluationId)
throws IOException {
throws IOException {
// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests. After completing all of your requests, call
// the "close" method on the client to safely clean up any remaining background resources.
try (AutoMlClient client = AutoMlClient.create()) {
// Get the full path of the model evaluation.
ModelEvaluationName modelEvaluationFullId =
ModelEvaluationName.of(projectId, "us-central1", modelId, modelEvaluationId);
ModelEvaluationName.of(projectId, "us-central1", modelId, modelEvaluationId);

// Get complete detail of the model evaluation.
ModelEvaluation modelEvaluation = client.getModelEvaluation(modelEvaluationFullId);
Expand All @@ -59,38 +58,41 @@ static void getModelEvaluation(String projectId, String modelId, String modelEva
System.out.format("\tseconds: %s\n", modelEvaluation.getCreateTime().getSeconds());
System.out.format("\tnanos: %s", modelEvaluation.getCreateTime().getNanos() / 1e9);
System.out.format(
"Evalution Example Count: %d\n", modelEvaluation.getEvaluatedExampleCount());
"Evalution Example Count: %d\n", modelEvaluation.getEvaluatedExampleCount());
// [END automl_language_sentiment_analysis_get_model_evaluation]
// [END automl_language_text_classification_get_model_evaluation]
// [END automl_translate_get_model_evaluation]
// [END automl_vision_classification_get_model_evaluation]
// [END automl_vision_object_detection_get_model_evaluation]
System.out.format("Entity Extraction Model Evaluation Metrics: %s\n",
modelEvaluation.getTextExtractionEvaluationMetrics());
System.out.format(
"Entity Extraction Model Evaluation Metrics: %s\n",
modelEvaluation.getTextExtractionEvaluationMetrics());
// [END automl_language_entity_extraction_get_model_evaluation]

// [START automl_language_sentiment_analysis_get_model_evaluation]
System.out.format("Sentiment Analysis Model Evaluation Metrics: %s\n",
modelEvaluation.getTextSentimentEvaluationMetrics());
System.out.format(
"Sentiment Analysis Model Evaluation Metrics: %s\n",
modelEvaluation.getTextSentimentEvaluationMetrics());
// [END automl_language_sentiment_analysis_get_model_evaluation]

// [START automl_language_text_classification_get_model_evaluation]
// [START automl_vision_classification_get_model_evaluation]
System.out.format("Classification Model Evaluation Metrics: %s\n",
modelEvaluation.getClassificationEvaluationMetrics());
System.out.format(
"Classification Model Evaluation Metrics: %s\n",
modelEvaluation.getClassificationEvaluationMetrics());
// [END automl_language_text_classification_get_model_evaluation]
// [END automl_vision_classification_get_model_evaluation]

// [START automl_translate_get_model_evaluation]
System.out.format(
"Translate Model Evaluation Metrics: %s\n",
modelEvaluation.getTranslationEvaluationMetrics());
"Translate Model Evaluation Metrics: %s\n",
modelEvaluation.getTranslationEvaluationMetrics());
// [END automl_translate_get_model_evaluation]


// [START automl_vision_object_detection_get_model_evaluation]
System.out.format("Object Detection Model Evaluation Metrics: %s\n",
modelEvaluation.getImageObjectDetectionEvaluationMetrics());
System.out.format(
"Object Detection Model Evaluation Metrics: %s\n",
modelEvaluation.getImageObjectDetectionEvaluationMetrics());
// [START automl_language_entity_extraction_get_model_evaluation]
// [START automl_language_sentiment_analysis_get_model_evaluation]
// [START automl_language_text_classification_get_model_evaluation]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
// [START automl_get_operation_status]
import com.google.cloud.automl.v1.AutoMlClient;
import com.google.longrunning.Operation;

import java.io.IOException;

class GetOperationStatus {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.google.cloud.automl.v1.GcsSource;
import com.google.cloud.automl.v1.InputConfig;
import com.google.protobuf.Empty;

import java.io.IOException;
import java.util.Arrays;
import java.util.concurrent.ExecutionException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.google.cloud.automl.v1.LocationName;
import com.google.cloud.automl.v1.OperationMetadata;
import com.google.cloud.automl.v1.TextExtractionDatasetMetadata;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.google.cloud.automl.v1.Model;
import com.google.cloud.automl.v1.OperationMetadata;
import com.google.cloud.automl.v1.TextExtractionModelMetadata;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.google.cloud.automl.v1.PredictionServiceClient;
import com.google.cloud.automl.v1.TextSegment;
import com.google.cloud.automl.v1.TextSnippet;

import java.io.IOException;

class LanguageEntityExtractionPredict {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.google.cloud.automl.v1.LocationName;
import com.google.cloud.automl.v1.OperationMetadata;
import com.google.cloud.automl.v1.TextSentimentDatasetMetadata;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.google.cloud.automl.v1.Model;
import com.google.cloud.automl.v1.OperationMetadata;
import com.google.cloud.automl.v1.TextSentimentModelMetadata;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.google.cloud.automl.v1.PredictResponse;
import com.google.cloud.automl.v1.PredictionServiceClient;
import com.google.cloud.automl.v1.TextSnippet;

import java.io.IOException;

class LanguageSentimentAnalysisPredict {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.google.cloud.automl.v1.LocationName;
import com.google.cloud.automl.v1.OperationMetadata;
import com.google.cloud.automl.v1.TextClassificationDatasetMetadata;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.google.cloud.automl.v1.Model;
import com.google.cloud.automl.v1.OperationMetadata;
import com.google.cloud.automl.v1.TextClassificationModelMetadata;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.google.cloud.automl.v1.PredictResponse;
import com.google.cloud.automl.v1.PredictionServiceClient;
import com.google.cloud.automl.v1.TextSnippet;

import java.io.IOException;

class LanguageTextClassificationPredict {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.google.cloud.automl.v1.Dataset;
import com.google.cloud.automl.v1.ListDatasetsRequest;
import com.google.cloud.automl.v1.LocationName;

import java.io.IOException;

class ListDatasets {
Expand All @@ -46,9 +45,7 @@ static void listDatasets(String projectId) throws IOException {
// A resource that represents Google Cloud Platform location.
LocationName projectLocation = LocationName.of(projectId, "us-central1");
ListDatasetsRequest request =
ListDatasetsRequest.newBuilder()
.setParent(projectLocation.toString())
.build();
ListDatasetsRequest.newBuilder().setParent(projectLocation.toString()).build();

// List all the datasets available in the region by applying filter.
System.out.println("List of datasets:");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.google.cloud.automl.v1.ListModelEvaluationsRequest;
import com.google.cloud.automl.v1.ModelEvaluation;
import com.google.cloud.automl.v1.ModelName;

import java.io.IOException;

class ListModelEvaluations {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.google.cloud.automl.v1.ListModelsRequest;
import com.google.cloud.automl.v1.LocationName;
import com.google.cloud.automl.v1.Model;

import java.io.IOException;

class ListModels {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.google.cloud.automl.v1.LocationName;
import com.google.longrunning.ListOperationsRequest;
import com.google.longrunning.Operation;

import java.io.IOException;

class ListOperationStatus {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.google.cloud.automl.v1.LocationName;
import com.google.cloud.automl.v1.OperationMetadata;
import com.google.cloud.automl.v1.TranslationDatasetMetadata;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.google.cloud.automl.v1.Model;
import com.google.cloud.automl.v1.OperationMetadata;
import com.google.cloud.automl.v1.TranslationModelMetadata;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.google.cloud.automl.v1.PredictResponse;
import com.google.cloud.automl.v1.PredictionServiceClient;
import com.google.cloud.automl.v1.TextSnippet;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.google.cloud.automl.v1.OperationMetadata;
import com.google.cloud.automl.v1.UndeployModelRequest;
import com.google.protobuf.Empty;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.google.cloud.automl.v1.ImageClassificationDatasetMetadata;
import com.google.cloud.automl.v1.LocationName;
import com.google.cloud.automl.v1.OperationMetadata;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.google.cloud.automl.v1.LocationName;
import com.google.cloud.automl.v1.Model;
import com.google.cloud.automl.v1.OperationMetadata;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.google.cloud.automl.v1.ModelName;
import com.google.cloud.automl.v1.OperationMetadata;
import com.google.protobuf.Empty;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.google.cloud.automl.v1.PredictResponse;
import com.google.cloud.automl.v1.PredictionServiceClient;
import com.google.protobuf.ByteString;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.google.cloud.automl.v1.ImageObjectDetectionDatasetMetadata;
import com.google.cloud.automl.v1.LocationName;
import com.google.cloud.automl.v1.OperationMetadata;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.google.cloud.automl.v1.LocationName;
import com.google.cloud.automl.v1.Model;
import com.google.cloud.automl.v1.OperationMetadata;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.google.cloud.automl.v1.ModelName;
import com.google.cloud.automl.v1.OperationMetadata;
import com.google.protobuf.Empty;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

Expand Down
Loading

0 comments on commit 64341f0

Please sign in to comment.