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,10 @@ 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 {
74
68
// Instantiate client for prediction service.
75
69
PredictionServiceClient predictionClient = PredictionServiceClient .create ();
76
70
@@ -87,9 +81,6 @@ public static void predict(
87
81
88
82
// Additional parameters that can be provided for prediction
89
83
Map <String , String > params = new HashMap <>();
90
- if (translationAllowFallback ) {
91
- params .put ("translation_allow_fallback" , "True" );//Allow Google Translation Model
92
- }
93
84
94
85
PredictResponse response = predictionClient .predict (name , payload , params );
95
86
TextSnippet translatedContent = response .getPayload (0 ).getTranslation ().getTranslatedContent ();
@@ -104,20 +95,16 @@ public static void main(String[] args) throws IOException {
104
95
}
105
96
106
97
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" );
98
+ ArgumentParser parser =
99
+ ArgumentParsers .newFor ("PredictionApi" )
100
+ .build ()
101
+ .defaultHelp (true )
102
+ .description ("Prediction API Operation" );
111
103
Subparsers subparsers = parser .addSubparsers ().dest ("command" );
112
104
113
105
Subparser predictParser = subparsers .addParser ("predict" );
114
106
predictParser .addArgument ("modelId" );
115
107
predictParser .addArgument ("filePath" );
116
- predictParser
117
- .addArgument ("translationAllowFallback" )
118
- .nargs ("?" )
119
- .type (Boolean .class )
120
- .setDefault (Boolean .FALSE );
121
108
122
109
String projectId = System .getenv ("PROJECT_ID" );
123
110
String computeRegion = System .getenv ("REGION_NAME" );
@@ -126,12 +113,7 @@ public static void argsHelper(String[] args, PrintStream out) throws IOException
126
113
try {
127
114
ns = parser .parseArgs (args );
128
115
if (ns .get ("command" ).equals ("predict" )) {
129
- predict (
130
- projectId ,
131
- computeRegion ,
132
- ns .getString ("modelId" ),
133
- ns .getString ("filePath" ),
134
- ns .getBoolean ("translationAllowFallback" ));
116
+ predict (projectId , computeRegion , ns .getString ("modelId" ), ns .getString ("filePath" ));
135
117
}
136
118
} catch (ArgumentParserException e ) {
137
119
parser .handleError (e );
0 commit comments