Skip to content

Commit aab3b73

Browse files
nirupa-kumarnnegrey
authored andcommitted
Automl (#1162)
* Test push * Vision AutoML * Vision AutoML updates + Translate AutoML * Translate README fixes * Fixing Kokoro failure issue * Language AutoML * Vision AutoML * Translate AutoML files added * Triggering tests * Triggering tests * Updates based on comments * Updates after review comments * Fixed build issue
1 parent 7ef8b81 commit aab3b73

File tree

6 files changed

+35
-39
lines changed

6 files changed

+35
-39
lines changed

language/automl/README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
<a href="https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/java-docs-samples&page=editor&open_in_editor=vision/beta/cloud-client/README.md">
44
<img alt="Open in Cloud Shell" src ="http://gstatic.com/cloudssh/images/open-btn.png"></a>
55

6-
[Google Cloud Natural Language API][language] provides feature detection for images.
6+
7+
[Google Cloud AutoML Natural Language API][language] provides feature detection for images.
8+
79
This API is part of the larger collection of Cloud Machine Learning APIs.
810

911
This sample Java application demonstrates how to access the Cloud Natural Language AutoML API
1012
using the [Google Cloud Client Library for Java][google-cloud-java].
1113

12-
[language]: https://cloud.google.com/language/docs/
14+
15+
[language]: https://cloud.google.com/language/automl/docs/
1316
[google-cloud-java]: https://github.com/GoogleCloudPlatform/google-cloud-java
1417

1518
## Set the environment variables
@@ -46,7 +49,7 @@ mvn exec:java -Dexec.mainClass="com.google.cloud.language.samples.DatasetApi" -D
4649

4750
#### Import data
4851
```
49-
mvn exec:java -Dexec.mainClass="com.google.cloud.language.samples.DatasetApi" -Dexec.args="import_data gs://java-docs-samples-testing/happiness.csv"
52+
mvn exec:java -Dexec.mainClass="com.google.cloud.language.samples.DatasetApi" -Dexec.args="import_data [dataset-id] gs://java-docs-samples-testing/happiness.csv"
5053
```
5154

5255
### Model API

translate/automl/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@
33
<a href="https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/java-docs-samples&page=editor&open_in_editor=vision/beta/cloud-client/README.md">
44
<img alt="Open in Cloud Shell" src ="http://gstatic.com/cloudssh/images/open-btn.png"></a>
55

6-
[Google Cloud Translate API][translate] provides feature AutoML.
6+
7+
[Google Cloud AutoML Translation API][translate] provides feature AutoML.
8+
79
This API is part of the larger collection of Cloud Machine Learning APIs.
810

911
This sample Java application demonstrates how to access the Cloud Translate AutoML API
1012
using the [Google Cloud Client Library for Java][google-cloud-java].
1113

14+
15+
[translate]: https://cloud.google.com/translate/automl/docs/
16+
[google-cloud-java]: https://github.com/GoogleCloudPlatform/google-cloud-java
17+
1218
## Set the environment variables
1319

1420
PROJECT_ID = [Id of the project]
@@ -43,7 +49,7 @@ mvn exec:java -Dexec.mainClass="com.google.cloud.translate.samples.DatasetApi" -
4349

4450
#### Import data
4551
```
46-
mvn exec:java -Dexec.mainClass="com.google.cloud.translate.samples.DatasetApi" -Dexec.args="import_data gs://java-docs-samples-testing/en-ja.csv"
52+
mvn exec:java -Dexec.mainClass="com.google.cloud.translate.samples.DatasetApi" -Dexec.args="import_data [dataset-id] gs://java-docs-samples-testing/en-ja.csv"
4753
```
4854

4955
### Model API

translate/automl/src/main/java/com/google/cloud/translate/automl/PredictionApi.java

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747

4848
/**
4949
* Google Cloud AutoML Translate API sample application. Example usage: mvn package exec:java
50-
* -Dexec.mainClass ='com.google.cloud.vision.samples.automl.PredictionApi' -Dexec.args='predict
51-
* [modelId] [path-to-image] [scoreThreshold]'
50+
* -Dexec.mainClass ='com.google.cloud.translate.automl.PredictionApi' -Dexec.args='predict
51+
* [modelId] [file-path]'
5252
*/
5353
public class PredictionApi {
5454

@@ -61,16 +61,11 @@ public class PredictionApi {
6161
* @param computeRegion the Region name.
6262
* @param modelId the Id of the model which will be used for text classification.
6363
* @param filePath the Local text file path of the content to be classified.
64-
* @param translationAllowFallback set to true to use a Google translation.
6564
* @throws IOException on Input/Output errors.
6665
*/
6766
public static void predict(
68-
String projectId,
69-
String computeRegion,
70-
String modelId,
71-
String filePath,
72-
boolean translationAllowFallback)
73-
throws IOException {
67+
String projectId, String computeRegion, String modelId, String filePath) throws IOException {
68+
7469
// Instantiate client for prediction service.
7570
PredictionServiceClient predictionClient = PredictionServiceClient.create();
7671

@@ -87,9 +82,6 @@ public static void predict(
8782

8883
// Additional parameters that can be provided for prediction
8984
Map<String, String> params = new HashMap<>();
90-
if (translationAllowFallback) {
91-
params.put("translation_allow_fallback", "True");//Allow Google Translation Model
92-
}
9385

9486
PredictResponse response = predictionClient.predict(name, payload, params);
9587
TextSnippet translatedContent = response.getPayload(0).getTranslation().getTranslatedContent();
@@ -104,20 +96,17 @@ public static void main(String[] args) throws IOException {
10496
}
10597

10698
public static void argsHelper(String[] args, PrintStream out) throws IOException {
107-
ArgumentParser parser = ArgumentParsers.newFor("PredictionApi")
108-
.build()
109-
.defaultHelp(true)
110-
.description("Prediction API Operation");
99+
ArgumentParser parser =
100+
ArgumentParsers.newFor("PredictionApi")
101+
.build()
102+
.defaultHelp(true)
103+
.description("Prediction API Operation");
104+
111105
Subparsers subparsers = parser.addSubparsers().dest("command");
112106

113107
Subparser predictParser = subparsers.addParser("predict");
114108
predictParser.addArgument("modelId");
115109
predictParser.addArgument("filePath");
116-
predictParser
117-
.addArgument("translationAllowFallback")
118-
.nargs("?")
119-
.type(Boolean.class)
120-
.setDefault(Boolean.FALSE);
121110

122111
String projectId = System.getenv("PROJECT_ID");
123112
String computeRegion = System.getenv("REGION_NAME");
@@ -126,12 +115,8 @@ public static void argsHelper(String[] args, PrintStream out) throws IOException
126115
try {
127116
ns = parser.parseArgs(args);
128117
if (ns.get("command").equals("predict")) {
129-
predict(
130-
projectId,
131-
computeRegion,
132-
ns.getString("modelId"),
133-
ns.getString("filePath"),
134-
ns.getBoolean("translationAllowFallback"));
118+
predict(projectId, computeRegion, ns.getString("modelId"), ns.getString("filePath"));
119+
135120
}
136121
} catch (ArgumentParserException e) {
137122
parser.handleError(e);

translate/automl/src/test/java/com/google/cloud/translate/automl/PredictionApiIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void tearDown() {
5555
@Test
5656
public void testPredict() throws Exception {
5757
// Act
58-
PredictionApi.predict(PROJECT_ID, COMPUTE_REGION, modelId, filePath,FALSE);
58+
PredictionApi.predict(PROJECT_ID, COMPUTE_REGION, modelId, filePath);
5959

6060
// Assert
6161
String got = bout.toString();

vision/automl/README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
<a href="https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/java-docs-samples&page=editor&open_in_editor=vision/beta/cloud-client/README.md">
44
<img alt="Open in Cloud Shell" src ="http://gstatic.com/cloudssh/images/open-btn.png"></a>
55

6-
[Google Cloud Vision API][vision] provides feature detection for images.
6+
[Google Cloud AutoML Vision API][vision] provides feature detection for images.
7+
78
This API is part of the larger collection of Cloud Machine Learning APIs.
89

910
This sample Java application demonstrates how to access the Cloud Vision API
1011
using the [Google Cloud Client Library for Java][google-cloud-java].
1112

12-
[vision]: https://cloud.google.com/vision/docs/
13+
14+
[vision]: https://cloud.google.com/vision/automl/docs/
1315
[google-cloud-java]: https://github.com/GoogleCloudPlatform/google-cloud-java
1416

1517
## Set the environment variables
@@ -45,14 +47,14 @@ mvn exec:java -Dexec.mainClass="com.google.cloud.vision.samples.automl.DatasetAp
4547

4648
#### Import data
4749
```
48-
mvn exec:java -Dexec.mainClass="com.google.cloud.vision.samples.automl.DatasetApi" -Dexec.args="import_data gs://java-docs-samples-testing/flower_traindata.csv"
50+
mvn exec:java -Dexec.mainClass="com.google.cloud.vision.samples.automl.DatasetApi" -Dexec.args="import_data [dataset-id] gs://java-docs-samples-testing/flower_traindata.csv"
4951
```
5052

5153
### Model API
5254

5355
#### Create Model
5456
```
55-
mvn exec:java -Dexec.mainClass="com.google.cloud.vision.samples.automl.ModelApi" -Dexec.args="create_model test_model"
57+
mvn exec:java -Dexec.mainClass="com.google.cloud.vision.samples.automl.ModelApi" -Dexec.args="create_model [dataset-id] test_model [training-budget] "
5658
```
5759

5860
#### List Models
@@ -77,7 +79,7 @@ mvn exec:java -Dexec.mainClass="com.google.cloud.vision.samples.automl.ModelApi"
7779

7880
#### Delete Model
7981
```
80-
mvn exec:java-Dexec.mainClass="com.google.cloud.vision.samples.automl.ModeltApi" -Dexec.args="delete_model [model-id]"
82+
mvn exec:java-Dexec.mainClass="com.google.cloud.vision.samples.automl.ModelApi" -Dexec.args="delete_model [model-id]"
8183
```
8284
### Predict API
8385

vision/automl/src/main/java/com/google/cloud/vision/samples/automl/PredictionApi.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public static void predict(
8989
// Additional parameters that can be provided for prediction e.g. Score Threshold
9090
Map<String, String> params = new HashMap<>();
9191
if (scoreThreshold != null) {
92-
params.put("scoreThreshold", scoreThreshold);
92+
params.put("score_threshold", scoreThreshold);
9393
}
9494
// Perform the AutoML Prediction request
9595
PredictResponse response = predictionClient.predict(name, examplePayload, params);

0 commit comments

Comments
 (0)