47
47
48
48
/**
49
49
* 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 ]'
52
52
*/
53
53
public class PredictionApi {
54
54
@@ -61,16 +61,11 @@ public class PredictionApi {
61
61
* @param computeRegion the Region name.
62
62
* @param modelId the Id of the model which will be used for text classification.
63
63
* @param filePath the Local text file path of the content to be classified.
64
- * @param translationAllowFallback set to true to use a Google translation.
65
64
* @throws IOException on Input/Output errors.
66
65
*/
67
66
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
+
74
69
// Instantiate client for prediction service.
75
70
PredictionServiceClient predictionClient = PredictionServiceClient .create ();
76
71
@@ -87,9 +82,6 @@ public static void predict(
87
82
88
83
// Additional parameters that can be provided for prediction
89
84
Map <String , String > params = new HashMap <>();
90
- if (translationAllowFallback ) {
91
- params .put ("translation_allow_fallback" , "True" );//Allow Google Translation Model
92
- }
93
85
94
86
PredictResponse response = predictionClient .predict (name , payload , params );
95
87
TextSnippet translatedContent = response .getPayload (0 ).getTranslation ().getTranslatedContent ();
@@ -104,20 +96,17 @@ public static void main(String[] args) throws IOException {
104
96
}
105
97
106
98
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
+
111
105
Subparsers subparsers = parser .addSubparsers ().dest ("command" );
112
106
113
107
Subparser predictParser = subparsers .addParser ("predict" );
114
108
predictParser .addArgument ("modelId" );
115
109
predictParser .addArgument ("filePath" );
116
- predictParser
117
- .addArgument ("translationAllowFallback" )
118
- .nargs ("?" )
119
- .type (Boolean .class )
120
- .setDefault (Boolean .FALSE );
121
110
122
111
String projectId = System .getenv ("PROJECT_ID" );
123
112
String computeRegion = System .getenv ("REGION_NAME" );
@@ -126,12 +115,8 @@ public static void argsHelper(String[] args, PrintStream out) throws IOException
126
115
try {
127
116
ns = parser .parseArgs (args );
128
117
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
+
135
120
}
136
121
} catch (ArgumentParserException e ) {
137
122
parser .handleError (e );
0 commit comments