Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
remove translate prediction fallback [(#1598)](GoogleCloudPlatform/py…
Browse files Browse the repository at this point in the history
  • Loading branch information
sirtorry authored and busunkim96 committed Sep 1, 2020
1 parent ba8eaff commit f7228f4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 28 deletions.
29 changes: 2 additions & 27 deletions samples/snippets/automl_translation_predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,13 @@
import os


def predict(
project_id,
compute_region,
model_id,
file_path,
translation_allow_fallback=False,
):
def predict(project_id, compute_region, model_id, file_path):
"""Translate the content."""
# [START automl_translation_predict]
# project_id = 'PROJECT_ID_HERE'
# compute_region = 'COMPUTE_REGION_HERE'
# model_id = 'MODEL_ID_HERE'
# file_path = '/local/path/to/file'
# translation_allow_fallback = True allows fallback to Google Translate

from google.cloud import automl_v1beta1 as automl

Expand All @@ -61,10 +54,7 @@ def predict(
payload = {"text_snippet": {"content": content}}

# params is additional domain-specific parameters.
# translation_allow_fallback allows to use Google translation model.
params = {}
if translation_allow_fallback:
params = {"translation_allow_fallback": "True"}

response = prediction_client.predict(model_full_id, payload, params)
translated_content = response.payload[0].translation.translated_content
Expand All @@ -84,26 +74,11 @@ def predict(
predict_parser = subparsers.add_parser("predict", help=predict.__doc__)
predict_parser.add_argument("model_id")
predict_parser.add_argument("file_path")
predict_parser.add_argument(
"translation_allow_fallback",
nargs="?",
choices=["False", "True"],
default="False",
)

project_id = os.environ["PROJECT_ID"]
compute_region = os.environ["REGION_NAME"]

args = parser.parse_args()

if args.command == "predict":
translation_allow_fallback = (
True if args.translation_allow_fallback == "True" else False
)
predict(
project_id,
compute_region,
args.model_id,
args.file_path,
translation_allow_fallback,
)
predict(project_id, compute_region, args.model_id, args.file_path)
2 changes: 1 addition & 1 deletion samples/snippets/predict_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
def test_predict(capsys):
model_id = "3128559826197068699"
automl_translation_predict.predict(
project_id, compute_region, model_id, "resources/input.txt", False
project_id, compute_region, model_id, "resources/input.txt"
)
out, _ = capsys.readouterr()
assert "Translated content: " in out

0 comments on commit f7228f4

Please sign in to comment.