Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove translate prediction fallback #1598

Merged
merged 1 commit into from
Jul 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 2 additions & 27 deletions translate/automl/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 translate/automl/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