2525import os
2626
2727
28- def predict (
29- project_id ,
30- compute_region ,
31- model_id ,
32- file_path ,
33- translation_allow_fallback = False ,
34- ):
28+ def predict (project_id , compute_region , model_id , file_path ):
3529 """Translate the content."""
3630 # [START automl_translation_predict]
3731 # project_id = 'PROJECT_ID_HERE'
3832 # compute_region = 'COMPUTE_REGION_HERE'
3933 # model_id = 'MODEL_ID_HERE'
4034 # file_path = '/local/path/to/file'
41- # translation_allow_fallback = True allows fallback to Google Translate
4235
4336 from google .cloud import automl_v1beta1 as automl
4437
@@ -61,10 +54,7 @@ def predict(
6154 payload = {"text_snippet" : {"content" : content }}
6255
6356 # params is additional domain-specific parameters.
64- # translation_allow_fallback allows to use Google translation model.
6557 params = {}
66- if translation_allow_fallback :
67- params = {"translation_allow_fallback" : "True" }
6858
6959 response = prediction_client .predict (model_full_id , payload , params )
7060 translated_content = response .payload [0 ].translation .translated_content
@@ -84,26 +74,11 @@ def predict(
8474 predict_parser = subparsers .add_parser ("predict" , help = predict .__doc__ )
8575 predict_parser .add_argument ("model_id" )
8676 predict_parser .add_argument ("file_path" )
87- predict_parser .add_argument (
88- "translation_allow_fallback" ,
89- nargs = "?" ,
90- choices = ["False" , "True" ],
91- default = "False" ,
92- )
9377
9478 project_id = os .environ ["PROJECT_ID" ]
9579 compute_region = os .environ ["REGION_NAME" ]
9680
9781 args = parser .parse_args ()
9882
9983 if args .command == "predict" :
100- translation_allow_fallback = (
101- True if args .translation_allow_fallback == "True" else False
102- )
103- predict (
104- project_id ,
105- compute_region ,
106- args .model_id ,
107- args .file_path ,
108- translation_allow_fallback ,
109- )
84+ predict (project_id , compute_region , args .model_id , args .file_path )
0 commit comments