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 */
5353public 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 );
0 commit comments