Skip to content

Commit b7e930f

Browse files
stephaniewang526jakubrauch
authored andcommitted
feat: revert "feat: remove automl beta samples" (GoogleCloudPlatform#3024)
Reverts GoogleCloudPlatform#3019
1 parent 26fecb1 commit b7e930f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+3537
-0
lines changed

automl/beta/pom.xml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<!--
2+
Copyright 2019 Google LLC
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
-->
13+
<project>
14+
<modelVersion>4.0.0</modelVersion>
15+
<groupId>com.example.automl</groupId>
16+
<artifactId>automl-google-cloud-samples</artifactId>
17+
<packaging>jar</packaging>
18+
19+
<!--
20+
The parent pom defines common style checks and testing strategies for our samples.
21+
Removing or replacing it should not affect the execution of the samples in anyway.
22+
-->
23+
<parent>
24+
<groupId>com.google.cloud.samples</groupId>
25+
<artifactId>shared-configuration</artifactId>
26+
<version>1.0.17</version>
27+
</parent>
28+
29+
<properties>
30+
<maven.compiler.target>11</maven.compiler.target>
31+
<maven.compiler.source>11</maven.compiler.source>
32+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
33+
</properties>
34+
35+
<!-- [START automl_java_dependencies] -->
36+
<!-- Using libraries-bom to manage versions.
37+
See https://github.com/GoogleCloudPlatform/cloud-opensource-java/wiki/The-Google-Cloud-Platform-Libraries-BOM -->
38+
<dependencyManagement>
39+
<dependencies>
40+
<dependency>
41+
<groupId>com.google.cloud</groupId>
42+
<artifactId>libraries-bom</artifactId>
43+
<version>5.2.0</version>
44+
<type>pom</type>
45+
<scope>import</scope>
46+
</dependency>
47+
</dependencies>
48+
</dependencyManagement>
49+
50+
<dependencies>
51+
<dependency>
52+
<groupId>com.google.cloud</groupId>
53+
<artifactId>google-cloud-automl</artifactId>
54+
</dependency>
55+
<dependency>
56+
<groupId>com.google.cloud</groupId>
57+
<artifactId>google-cloud-bigquery</artifactId>
58+
</dependency>
59+
<!-- [END automl_java_dependencies] -->
60+
<dependency>
61+
<groupId>com.google.cloud</groupId>
62+
<artifactId>google-cloud-storage</artifactId>
63+
</dependency>
64+
<dependency>
65+
<groupId>net.sourceforge.argparse4j</groupId>
66+
<artifactId>argparse4j</artifactId>
67+
<version>0.8.1</version>
68+
</dependency>
69+
70+
<!-- Test dependencies -->
71+
<dependency>
72+
<groupId>junit</groupId>
73+
<artifactId>junit</artifactId>
74+
<version>4.13</version>
75+
<scope>test</scope>
76+
</dependency>
77+
<dependency>
78+
<groupId>com.google.truth</groupId>
79+
<artifactId>truth</artifactId>
80+
<version>1.0.1</version>
81+
<scope>test</scope>
82+
</dependency>
83+
<!-- [START automl_java_dependencies] -->
84+
</dependencies>
85+
<!-- [END automl_java_dependencies] -->
86+
</project>
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.automl;
18+
19+
// [START automl_batch_predict_beta]
20+
import com.google.api.gax.longrunning.OperationFuture;
21+
import com.google.cloud.automl.v1beta1.BatchPredictInputConfig;
22+
import com.google.cloud.automl.v1beta1.BatchPredictOutputConfig;
23+
import com.google.cloud.automl.v1beta1.BatchPredictRequest;
24+
import com.google.cloud.automl.v1beta1.BatchPredictResult;
25+
import com.google.cloud.automl.v1beta1.GcsDestination;
26+
import com.google.cloud.automl.v1beta1.GcsSource;
27+
import com.google.cloud.automl.v1beta1.ModelName;
28+
import com.google.cloud.automl.v1beta1.OperationMetadata;
29+
import com.google.cloud.automl.v1beta1.PredictionServiceClient;
30+
import java.io.IOException;
31+
import java.util.concurrent.ExecutionException;
32+
33+
class BatchPredict {
34+
35+
static void batchPredict() throws IOException, ExecutionException, InterruptedException {
36+
// TODO(developer): Replace these variables before running the sample.
37+
String projectId = "YOUR_PROJECT_ID";
38+
String modelId = "YOUR_MODEL_ID";
39+
String inputUri = "gs://YOUR_BUCKET_ID/path_to_your_input_csv_or_jsonl";
40+
String outputUri = "gs://YOUR_BUCKET_ID/path_to_save_results/";
41+
batchPredict(projectId, modelId, inputUri, outputUri);
42+
}
43+
44+
static void batchPredict(String projectId, String modelId, String inputUri, String outputUri)
45+
throws IOException, ExecutionException, InterruptedException {
46+
// Initialize client that will be used to send requests. This client only needs to be created
47+
// once, and can be reused for multiple requests. After completing all of your requests, call
48+
// the "close" method on the client to safely clean up any remaining background resources.
49+
try (PredictionServiceClient client = PredictionServiceClient.create()) {
50+
// Get the full path of the model.
51+
ModelName name = ModelName.of(projectId, "us-central1", modelId);
52+
53+
// Configure the source of the file from a GCS bucket
54+
GcsSource gcsSource = GcsSource.newBuilder().addInputUris(inputUri).build();
55+
BatchPredictInputConfig inputConfig =
56+
BatchPredictInputConfig.newBuilder().setGcsSource(gcsSource).build();
57+
58+
// Configure where to store the output in a GCS bucket
59+
GcsDestination gcsDestination =
60+
GcsDestination.newBuilder().setOutputUriPrefix(outputUri).build();
61+
BatchPredictOutputConfig outputConfig =
62+
BatchPredictOutputConfig.newBuilder().setGcsDestination(gcsDestination).build();
63+
64+
// Build the request that will be sent to the API
65+
BatchPredictRequest request =
66+
BatchPredictRequest.newBuilder()
67+
.setName(name.toString())
68+
.setInputConfig(inputConfig)
69+
.setOutputConfig(outputConfig)
70+
.build();
71+
72+
// Start an asynchronous request
73+
OperationFuture<BatchPredictResult, OperationMetadata> future =
74+
client.batchPredictAsync(request);
75+
76+
System.out.println("Waiting for operation to complete...");
77+
BatchPredictResult response = future.get();
78+
System.out.println("Batch Prediction results saved to specified Cloud Storage bucket.");
79+
}
80+
}
81+
}
82+
// [END automl_batch_predict_beta]
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.automl;
18+
19+
// [START automl_cancel_operation_beta]
20+
import com.google.cloud.automl.v1beta1.AutoMlClient;
21+
import java.io.IOException;
22+
23+
class CancelOperation {
24+
25+
static void cancelOperation() throws IOException {
26+
// TODO(developer): Replace these variables before running the sample.
27+
String projectId = "YOUR_PROJECT_ID";
28+
String location = "us-central1";
29+
String operationId = "YOUR_OPERATION_ID";
30+
String operationFullId =
31+
String.format("projects/%s/locations/%s/operations/%s", projectId, location, operationId);
32+
cancelOperation(operationFullId);
33+
}
34+
35+
static void cancelOperation(String operationFullId) throws IOException {
36+
// Initialize client that will be used to send requests. This client only needs to be created
37+
// once, and can be reused for multiple requests. After completing all of your requests, call
38+
// the "close" method on the client to safely clean up any remaining background resources.
39+
try (AutoMlClient client = AutoMlClient.create()) {
40+
client.getOperationsClient().cancelOperation(operationFullId);
41+
System.out.println("Operation cancelled");
42+
}
43+
}
44+
}
45+
// [END automl_cancel_operation_beta]
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.automl;
18+
19+
// [START automl_delete_dataset_beta]
20+
import com.google.cloud.automl.v1beta1.AutoMlClient;
21+
import com.google.cloud.automl.v1beta1.DatasetName;
22+
import com.google.protobuf.Empty;
23+
import java.io.IOException;
24+
import java.util.concurrent.ExecutionException;
25+
26+
class DeleteDataset {
27+
28+
static void deleteDataset() throws IOException, ExecutionException, InterruptedException {
29+
// TODO(developer): Replace these variables before running the sample.
30+
String projectId = "YOUR_PROJECT_ID";
31+
String datasetId = "YOUR_DATASET_ID";
32+
deleteDataset(projectId, datasetId);
33+
}
34+
35+
// Delete a dataset
36+
static void deleteDataset(String projectId, String datasetId)
37+
throws IOException, ExecutionException, InterruptedException {
38+
// Initialize client that will be used to send requests. This client only needs to be created
39+
// once, and can be reused for multiple requests. After completing all of your requests, call
40+
// the "close" method on the client to safely clean up any remaining background resources.
41+
try (AutoMlClient client = AutoMlClient.create()) {
42+
// Get the full path of the dataset.
43+
DatasetName datasetFullId = DatasetName.of(projectId, "us-central1", datasetId);
44+
Empty response = client.deleteDatasetAsync(datasetFullId).get();
45+
System.out.format("Dataset deleted. %s%n", response);
46+
}
47+
}
48+
}
49+
// [END automl_delete_dataset_beta]
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.automl;
18+
19+
// [START automl_delete_model_beta]
20+
import com.google.cloud.automl.v1beta1.AutoMlClient;
21+
import com.google.cloud.automl.v1beta1.ModelName;
22+
import com.google.protobuf.Empty;
23+
import java.io.IOException;
24+
import java.util.concurrent.ExecutionException;
25+
26+
class DeleteModel {
27+
28+
public static void main(String[] args)
29+
throws IOException, ExecutionException, InterruptedException {
30+
// TODO(developer): Replace these variables before running the sample.
31+
String projectId = "YOUR_PROJECT_ID";
32+
String modelId = "YOUR_MODEL_ID";
33+
deleteModel(projectId, modelId);
34+
}
35+
36+
// Delete a model
37+
static void deleteModel(String projectId, String modelId)
38+
throws IOException, ExecutionException, InterruptedException {
39+
// Initialize client that will be used to send requests. This client only needs to be created
40+
// once, and can be reused for multiple requests. After completing all of your requests, call
41+
// the "close" method on the client to safely clean up any remaining background resources.
42+
try (AutoMlClient client = AutoMlClient.create()) {
43+
// Get the full path of the model.
44+
ModelName modelFullId = ModelName.of(projectId, "us-central1", modelId);
45+
46+
// Delete a model.
47+
Empty response = client.deleteModelAsync(modelFullId).get();
48+
49+
System.out.println("Model deletion started...");
50+
System.out.println(String.format("Model deleted. %s", response));
51+
}
52+
}
53+
}
54+
// [END automl_delete_model_beta]
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.automl;
18+
19+
// [START automl_deploy_model_beta]
20+
import com.google.api.gax.longrunning.OperationFuture;
21+
import com.google.cloud.automl.v1beta1.AutoMlClient;
22+
import com.google.cloud.automl.v1beta1.DeployModelRequest;
23+
import com.google.cloud.automl.v1beta1.ModelName;
24+
import com.google.cloud.automl.v1beta1.OperationMetadata;
25+
import com.google.protobuf.Empty;
26+
import java.io.IOException;
27+
import java.util.concurrent.ExecutionException;
28+
29+
class DeployModel {
30+
31+
public static void main(String[] args)
32+
throws IOException, ExecutionException, InterruptedException {
33+
// TODO(developer): Replace these variables before running the sample.
34+
String projectId = "YOUR_PROJECT_ID";
35+
String modelId = "YOUR_MODEL_ID";
36+
deployModel(projectId, modelId);
37+
}
38+
39+
// Deploy a model for prediction
40+
static void deployModel(String projectId, String modelId)
41+
throws IOException, ExecutionException, InterruptedException {
42+
// Initialize client that will be used to send requests. This client only needs to be created
43+
// once, and can be reused for multiple requests. After completing all of your requests, call
44+
// the "close" method on the client to safely clean up any remaining background resources.
45+
try (AutoMlClient client = AutoMlClient.create()) {
46+
// Get the full path of the model.
47+
ModelName modelFullId = ModelName.of(projectId, "us-central1", modelId);
48+
DeployModelRequest request =
49+
DeployModelRequest.newBuilder().setName(modelFullId.toString()).build();
50+
OperationFuture<Empty, OperationMetadata> future = client.deployModelAsync(request);
51+
52+
future.get();
53+
System.out.println("Model deployment finished");
54+
}
55+
}
56+
}
57+
// [END automl_deploy_model_beta]

0 commit comments

Comments
 (0)