25
25
import os
26
26
27
27
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 ):
35
29
"""Translate the content."""
36
30
# [START automl_translation_predict]
37
31
# project_id = 'PROJECT_ID_HERE'
38
32
# compute_region = 'COMPUTE_REGION_HERE'
39
33
# model_id = 'MODEL_ID_HERE'
40
34
# file_path = '/local/path/to/file'
41
- # translation_allow_fallback = True allows fallback to Google Translate
42
35
43
36
from google .cloud import automl_v1beta1 as automl
44
37
@@ -61,10 +54,7 @@ def predict(
61
54
payload = {"text_snippet" : {"content" : content }}
62
55
63
56
# params is additional domain-specific parameters.
64
- # translation_allow_fallback allows to use Google translation model.
65
57
params = {}
66
- if translation_allow_fallback :
67
- params = {"translation_allow_fallback" : "True" }
68
58
69
59
response = prediction_client .predict (model_full_id , payload , params )
70
60
translated_content = response .payload [0 ].translation .translated_content
@@ -84,26 +74,11 @@ def predict(
84
74
predict_parser = subparsers .add_parser ("predict" , help = predict .__doc__ )
85
75
predict_parser .add_argument ("model_id" )
86
76
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
- )
93
77
94
78
project_id = os .environ ["PROJECT_ID" ]
95
79
compute_region = os .environ ["REGION_NAME" ]
96
80
97
81
args = parser .parse_args ()
98
82
99
83
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