Skip to content
This repository was archived by the owner on Dec 31, 2023. It is now read-only.

Commit 31f06c5

Browse files
sirtorrybusunkim96
authored andcommitted
remove translate prediction fallback [(#1598)](GoogleCloudPlatform/python-docs-samples#1598)
1 parent 2c98635 commit 31f06c5

File tree

2 files changed

+3
-28
lines changed

2 files changed

+3
-28
lines changed

samples/snippets/automl_translation_predict.py

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,13 @@
2525
import 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)

samples/snippets/predict_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
def test_predict(capsys):
2626
model_id = "3128559826197068699"
2727
automl_translation_predict.predict(
28-
project_id, compute_region, model_id, "resources/input.txt", False
28+
project_id, compute_region, model_id, "resources/input.txt"
2929
)
3030
out, _ = capsys.readouterr()
3131
assert "Translated content: " in out

0 commit comments

Comments
 (0)