From 8039dc10ab8b3d8ef9587b0dc9150b5be0a140ab Mon Sep 17 00:00:00 2001 From: Mike Ganbold Date: Thu, 13 Feb 2020 16:22:07 -0800 Subject: [PATCH 1/6] Translate: migrate published b v3 tch samples --- ...late_v3_batch_translate_text_with_model.py | 65 +++++++++++++++++ ...v3_batch_translate_text_with_model_test.py | 46 ++++++++++++ .../translate_v3_batch_translate_text.py | 54 ++++++++++++++ .../translate_v3_batch_translate_text_test.py | 43 +++++++++++ ...e_v3_batch_translate_text_with_glossary.py | 72 +++++++++++++++++++ ...batch_translate_text_with_glossary_test.py | 64 +++++++++++++++++ 6 files changed, 344 insertions(+) create mode 100644 translate/automl/translate_v3_batch_translate_text_with_model.py create mode 100644 translate/automl/translate_v3_batch_translate_text_with_model_test.py create mode 100644 translate/cloud-client/translate_v3_batch_translate_text.py create mode 100644 translate/cloud-client/translate_v3_batch_translate_text_test.py create mode 100644 translate/cloud-client/translate_v3_batch_translate_text_with_glossary.py create mode 100644 translate/cloud-client/translate_v3_batch_translate_text_with_glossary_test.py diff --git a/translate/automl/translate_v3_batch_translate_text_with_model.py b/translate/automl/translate_v3_batch_translate_text_with_model.py new file mode 100644 index 000000000000..25409f5ccfe8 --- /dev/null +++ b/translate/automl/translate_v3_batch_translate_text_with_model.py @@ -0,0 +1,65 @@ +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +# [START translate_v3_batch_translate_text_with_model] +from google.cloud import translate + + +def batch_translate_text_with_model( + input_uri="YOUR_INPUT_URI", + output_uri="YOUR_OUTPUT_URI", + project_id="YOUR_PROJECT_ID", + model_id="YOUR_MODEL_ID", +): + """Batch translate text using Translation model. + Model can be AutoML or General[built-in] model. """ + + client = translate.TranslationServiceClient() + + gcs_source = {"input_uri": input_uri} + location = "us-central1" + + # Supported language codes: https://cloud.google.com/translate/docs/languages + target_lang = "ja" + mime_type = "text/plain" # Can be "text/plain" or "text/html". + input_configs_element = {"gcs_source": gcs_source, "mime_type": mime_type} + input_configs = [input_configs_element] + gcs_destination = {"output_uri_prefix": output_uri} + output_config = {"gcs_destination": gcs_destination} + parent = client.location_path(project_id, location) + + model_path = "projects/{}/locations/{}/models/{}".format( + project_id, "us-central1", model_id # The location of AutoML model + ) + models = {target_lang: model_path} + + operation = client.batch_translate_text( + parent=parent, + source_language_code="en", + target_language_codes=[target_lang], # Up to 10 language codes here. + input_configs=input_configs, + output_config=output_config, + models=models, + ) + + print(u"Waiting for operation to complete...") + response = operation.result() + + # Display the translation for each input text provided + print(u"Total Characters: {}".format(response.total_characters)) + print(u"Translated Characters: {}".format(response.translated_characters)) + + +# [END translate_v3_batch_translate_text_with_model] diff --git a/translate/automl/translate_v3_batch_translate_text_with_model_test.py b/translate/automl/translate_v3_batch_translate_text_with_model_test.py new file mode 100644 index 000000000000..74b044f43527 --- /dev/null +++ b/translate/automl/translate_v3_batch_translate_text_with_model_test.py @@ -0,0 +1,46 @@ +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import pytest +import uuid +import translate_v3_batch_translate_text_with_model +from google.cloud import storage + +PROJECT_ID = os.environ["GCLOUD_PROJECT"] +MODEL_ID = "TRL3128559826197068699" + + +@pytest.fixture(scope="function") +def bucket(): + """Create a temporary bucket to store annotation output.""" + bucket_name = str(uuid.uuid1()) + storage_client = storage.Client() + bucket = storage_client.create_bucket(bucket_name) + + yield bucket + + bucket.delete(force=True) + + +def test_batch_translate_text_with_model(capsys, bucket): + translate_v3_batch_translate_text_with_model.batch_translate_text_with_model( + "gs://cloud-samples-data/translation/custom_model_text.txt", + "gs://{}/translation/BATCH_TRANSLATION_OUTPUT/".format(bucket.name), + PROJECT_ID, + MODEL_ID, + ) + out, _ = capsys.readouterr() + assert "Total Characters: 15" in out + assert "Translated Characters: 15" in out diff --git a/translate/cloud-client/translate_v3_batch_translate_text.py b/translate/cloud-client/translate_v3_batch_translate_text.py new file mode 100644 index 000000000000..8c7f3cf746d2 --- /dev/null +++ b/translate/cloud-client/translate_v3_batch_translate_text.py @@ -0,0 +1,54 @@ +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# [START translate_v3_batch_translate_text] +from google.cloud import translate + + +def batch_translate_text( + input_uri="YOUR_INPUT_URI", + output_uri="YOUR_OUTPUT_URI", + project_id="YOUR_PROJECT_ID" +): + """Translates a batch of texts on GCS and stores the result in a GCS location.""" + + client = translate.TranslationServiceClient() + + # Supported language codes: https://cloud.google.com/translate/docs/language + target_lang = "ja" + location = "us-central1" + gcs_source = {"input_uri": input_uri} + + mime_type = "text/plain" # Can be "text/plain" or "text/html". + input_configs_element = {"gcs_source": gcs_source, "mime_type": mime_type} + input_configs = [input_configs_element] + gcs_destination = {"output_uri_prefix": output_uri} + output_config = {"gcs_destination": gcs_destination} + parent = client.location_path(project_id, location) + + operation = client.batch_translate_text( + parent=parent, + source_language_code="en", + target_language_codes=[target_lang], # Up to 10 language codes here. + input_configs=input_configs, + output_config=output_config) + + print(u"Waiting for operation to complete...") + response = operation.result(90) + + print(u"Total Characters: {}".format(response.total_characters)) + print(u"Translated Characters: {}".format(response.translated_characters)) + + +# [END translate_v3_batch_translate_text] diff --git a/translate/cloud-client/translate_v3_batch_translate_text_test.py b/translate/cloud-client/translate_v3_batch_translate_text_test.py new file mode 100644 index 000000000000..c6e1e6e352e7 --- /dev/null +++ b/translate/cloud-client/translate_v3_batch_translate_text_test.py @@ -0,0 +1,43 @@ +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import pytest +import translate_v3_batch_translate_text +import uuid +from google.cloud import storage + +PROJECT_ID = os.environ["GCLOUD_PROJECT"] + + +@pytest.fixture(scope="function") +def bucket(): + """Create a temporary bucket to store annotation output.""" + bucket_name = str(uuid.uuid1()) + storage_client = storage.Client() + bucket = storage_client.create_bucket(bucket_name) + + yield bucket + + bucket.delete(force=True) + + +def test_batch_translate_text(capsys, bucket): + translate_v3_batch_translate_text.batch_translate_text( + "gs://cloud-samples-data/translation/text.txt", + "gs://{}/translation/BATCH_TRANSLATION_OUTPUT/".format(bucket.name), + PROJECT_ID, + ) + out, _ = capsys.readouterr() + assert "Total Characters" in out diff --git a/translate/cloud-client/translate_v3_batch_translate_text_with_glossary.py b/translate/cloud-client/translate_v3_batch_translate_text_with_glossary.py new file mode 100644 index 000000000000..ebde8bc67df0 --- /dev/null +++ b/translate/cloud-client/translate_v3_batch_translate_text_with_glossary.py @@ -0,0 +1,72 @@ +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +# [START translate_v3_batch_translate_text_with_glossary] +from google.cloud import translate + + +def batch_translate_text_with_glossary( + input_uri="YOUR_INPUT_URI", + output_uri="YOUR_OUTPUT_URI", + project_id="YOUR_PROJECT_ID", + glossary_id="YOUR_GLOSSARY_ID", +): + """Translates a batch of texts on GCS and stores the result in a GCS location. + Glossary is applied for translation.""" + + client = translate.TranslationServiceClient() + + # Supported language codes: https://cloud.google.com/translate/docs/languages + target_lang = "ja" + location = "us-central1" + gcs_source = {"input_uri": input_uri} + + mime_type = "text/plain" # Can be "text/plain" or "text/html". + input_configs_element = {"gcs_source": gcs_source, "mime_type": mime_type} + input_configs = [input_configs_element] + gcs_destination = {"output_uri_prefix": output_uri} + output_config = {"gcs_destination": gcs_destination} + + parent = client.location_path(project_id, location) + + # glossary is a custom dictionary Translation API uses + # to translate the domain-specific terminology. + glossary_path = client.glossary_path( + project_id, "us-central1", glossary_id # The location of the glossary + ) + + glossary_config = translate.types.TranslateTextGlossaryConfig( + glossary=glossary_path + ) + + glossaries = {target_lang: glossary_config} # target lang as key + + operation = client.batch_translate_text( + parent=parent, + source_language_code="en", + target_language_codes=[target_lang], # Up to 10 language codes here. + input_configs=input_configs, + glossaries=glossaries, + output_config=output_config, + ) + + print(u"Waiting for operation to complete...") + response = operation.result(90) + + print(u"Total Characters: {}".format(response.total_characters)) + print(u"Translated Characters: {}".format(response.translated_characters)) + + +# [END translate_v3_batch_translate_text_with_glossary] diff --git a/translate/cloud-client/translate_v3_batch_translate_text_with_glossary_test.py b/translate/cloud-client/translate_v3_batch_translate_text_with_glossary_test.py new file mode 100644 index 000000000000..87d97b73c044 --- /dev/null +++ b/translate/cloud-client/translate_v3_batch_translate_text_with_glossary_test.py @@ -0,0 +1,64 @@ +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import pytest +import uuid +import translate_v3_batch_translate_text_with_glossary +import translate_v3_create_glossary +import translate_v3_delete_glossary +from google.cloud import storage + +PROJECT_ID = os.environ["GCLOUD_PROJECT"] +GLOSSARY_INPUT_URI = "gs://cloud-samples-data/translation/glossary_ja.csv" + + +@pytest.fixture(scope="session") +def glossary(): + """Get the ID of a glossary available to session (do not mutate/delete).""" + glossary_id = "must-start-with-letters-" + str(uuid.uuid1()) + translate_v3_create_glossary.create_glossary( + PROJECT_ID, GLOSSARY_INPUT_URI, glossary_id + ) + + yield glossary_id + + try: + translate_v3_delete_glossary.delete_glossary(PROJECT_ID, glossary_id) + except Exception: + pass + + +@pytest.fixture(scope="function") +def bucket(): + """Create a temporary bucket to store annotation output.""" + bucket_name = str(uuid.uuid1()) + storage_client = storage.Client() + bucket = storage_client.create_bucket(bucket_name) + + yield bucket + + bucket.delete(force=True) + + +def test_batch_translate_text_with_glossary(capsys, bucket, glossary): + translate_v3_batch_translate_text_with_glossary.batch_translate_text_with_glossary( + "gs://cloud-samples-data/translation/text_with_glossary.txt", + "gs://{}/translation/BATCH_TRANSLATION_OUTPUT/".format(bucket.name), + PROJECT_ID, + glossary, + ) + + out, _ = capsys.readouterr() + assert "Total Characters: 9" in out From 2067cf6d5e48816599a8d0b1eb265f3071ab990e Mon Sep 17 00:00:00 2001 From: Mike Ganbold Date: Thu, 13 Feb 2020 17:48:00 -0800 Subject: [PATCH 2/6] added missing requirements --- translate/automl/requirements.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/translate/automl/requirements.txt b/translate/automl/requirements.txt index 08350c58c60c..6143ccba3617 100644 --- a/translate/automl/requirements.txt +++ b/translate/automl/requirements.txt @@ -1 +1,3 @@ +google-cloud-translate==2.0.0 +google-cloud-storage==1.19.1 google-cloud-automl==0.9.0 From 64e1670149685322de4e09d665b865875644ad46 Mon Sep 17 00:00:00 2001 From: Mike Ganbold Date: Tue, 25 Feb 2020 12:44:17 -0800 Subject: [PATCH 3/6] extended wait time --- .../translate_v3_batch_translate_text_with_glossary.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/translate/cloud-client/translate_v3_batch_translate_text_with_glossary.py b/translate/cloud-client/translate_v3_batch_translate_text_with_glossary.py index ebde8bc67df0..9cec31d9a752 100644 --- a/translate/cloud-client/translate_v3_batch_translate_text_with_glossary.py +++ b/translate/cloud-client/translate_v3_batch_translate_text_with_glossary.py @@ -63,7 +63,7 @@ def batch_translate_text_with_glossary( ) print(u"Waiting for operation to complete...") - response = operation.result(90) + response = operation.result(120) print(u"Total Characters: {}".format(response.total_characters)) print(u"Translated Characters: {}".format(response.translated_characters)) From 62af28cbcab1db3b8a7e47867e70f7c613c1df17 Mon Sep 17 00:00:00 2001 From: Mike Ganbold Date: Wed, 26 Feb 2020 13:13:22 -0800 Subject: [PATCH 4/6] inlined some vals and specified input and output --- ...late_v3_batch_translate_text_with_model.py | 25 ++++++++++--------- .../translate_v3_batch_translate_text.py | 18 ++++++------- ...e_v3_batch_translate_text_with_glossary.py | 18 ++++++------- 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/translate/automl/translate_v3_batch_translate_text_with_model.py b/translate/automl/translate_v3_batch_translate_text_with_model.py index 25409f5ccfe8..e9307722c958 100644 --- a/translate/automl/translate_v3_batch_translate_text_with_model.py +++ b/translate/automl/translate_v3_batch_translate_text_with_model.py @@ -18,8 +18,8 @@ def batch_translate_text_with_model( - input_uri="YOUR_INPUT_URI", - output_uri="YOUR_OUTPUT_URI", + input_uri="gs://YOUR_BUCKET_ID/path/to/your/file.type", + output_uri="gs://YOUR_BUCKET_ID/path/to/save/results/", project_id="YOUR_PROJECT_ID", model_id="YOUR_MODEL_ID", ): @@ -31,25 +31,26 @@ def batch_translate_text_with_model( gcs_source = {"input_uri": input_uri} location = "us-central1" - # Supported language codes: https://cloud.google.com/translate/docs/languages - target_lang = "ja" - mime_type = "text/plain" # Can be "text/plain" or "text/html". - input_configs_element = {"gcs_source": gcs_source, "mime_type": mime_type} - input_configs = [input_configs_element] + input_configs_element = { + "gcs_source": gcs_source, + "mime_type": "text/plain" # Can be "text/plain" or "text/html". + } gcs_destination = {"output_uri_prefix": output_uri} output_config = {"gcs_destination": gcs_destination} parent = client.location_path(project_id, location) model_path = "projects/{}/locations/{}/models/{}".format( - project_id, "us-central1", model_id # The location of AutoML model + project_id, "us-central1", model_id # The location of AutoML model. ) - models = {target_lang: model_path} + + # Supported language codes: https://cloud.google.com/translate/docs/languages + models = {"ja": model_path} # takes a target lang as key. operation = client.batch_translate_text( parent=parent, source_language_code="en", - target_language_codes=[target_lang], # Up to 10 language codes here. - input_configs=input_configs, + target_language_codes=["ja"], # Up to 10 language codes here. + input_configs=[input_configs_element], output_config=output_config, models=models, ) @@ -57,7 +58,7 @@ def batch_translate_text_with_model( print(u"Waiting for operation to complete...") response = operation.result() - # Display the translation for each input text provided + # Display the translation for each input text provided. print(u"Total Characters: {}".format(response.total_characters)) print(u"Translated Characters: {}".format(response.translated_characters)) diff --git a/translate/cloud-client/translate_v3_batch_translate_text.py b/translate/cloud-client/translate_v3_batch_translate_text.py index 8c7f3cf746d2..37a5e97c144e 100644 --- a/translate/cloud-client/translate_v3_batch_translate_text.py +++ b/translate/cloud-client/translate_v3_batch_translate_text.py @@ -17,31 +17,31 @@ def batch_translate_text( - input_uri="YOUR_INPUT_URI", - output_uri="YOUR_OUTPUT_URI", + input_uri="gs://YOUR_BUCKET_ID/path/to/your/file.type", + output_uri="gs://YOUR_BUCKET_ID/path/to/save/results/", project_id="YOUR_PROJECT_ID" ): """Translates a batch of texts on GCS and stores the result in a GCS location.""" client = translate.TranslationServiceClient() - # Supported language codes: https://cloud.google.com/translate/docs/language - target_lang = "ja" location = "us-central1" gcs_source = {"input_uri": input_uri} - mime_type = "text/plain" # Can be "text/plain" or "text/html". - input_configs_element = {"gcs_source": gcs_source, "mime_type": mime_type} - input_configs = [input_configs_element] + input_configs_element = { + "gcs_source": gcs_source, + "mime_type": "text/plain" # Can be "text/plain" or "text/html". + } gcs_destination = {"output_uri_prefix": output_uri} output_config = {"gcs_destination": gcs_destination} parent = client.location_path(project_id, location) + # Supported language codes: https://cloud.google.com/translate/docs/language operation = client.batch_translate_text( parent=parent, source_language_code="en", - target_language_codes=[target_lang], # Up to 10 language codes here. - input_configs=input_configs, + target_language_codes=["ja"], # Up to 10 language codes here. + input_configs=[input_configs_element], output_config=output_config) print(u"Waiting for operation to complete...") diff --git a/translate/cloud-client/translate_v3_batch_translate_text_with_glossary.py b/translate/cloud-client/translate_v3_batch_translate_text_with_glossary.py index 9cec31d9a752..3b29da960567 100644 --- a/translate/cloud-client/translate_v3_batch_translate_text_with_glossary.py +++ b/translate/cloud-client/translate_v3_batch_translate_text_with_glossary.py @@ -18,8 +18,8 @@ def batch_translate_text_with_glossary( - input_uri="YOUR_INPUT_URI", - output_uri="YOUR_OUTPUT_URI", + input_uri="gs://YOUR_BUCKET_ID/path/to/your/file.type", + output_uri="gs://YOUR_BUCKET_ID/path/to/save/results/", project_id="YOUR_PROJECT_ID", glossary_id="YOUR_GLOSSARY_ID", ): @@ -29,13 +29,13 @@ def batch_translate_text_with_glossary( client = translate.TranslationServiceClient() # Supported language codes: https://cloud.google.com/translate/docs/languages - target_lang = "ja" location = "us-central1" gcs_source = {"input_uri": input_uri} - mime_type = "text/plain" # Can be "text/plain" or "text/html". - input_configs_element = {"gcs_source": gcs_source, "mime_type": mime_type} - input_configs = [input_configs_element] + input_configs_element = { + "gcs_source": gcs_source, + "mime_type": "text/plain" # Can be "text/plain" or "text/html". + } gcs_destination = {"output_uri_prefix": output_uri} output_config = {"gcs_destination": gcs_destination} @@ -51,13 +51,13 @@ def batch_translate_text_with_glossary( glossary=glossary_path ) - glossaries = {target_lang: glossary_config} # target lang as key + glossaries = {"ja": glossary_config} # target lang as key operation = client.batch_translate_text( parent=parent, source_language_code="en", - target_language_codes=[target_lang], # Up to 10 language codes here. - input_configs=input_configs, + target_language_codes=["ja"], # Up to 10 language codes here. + input_configs=[input_configs_element], glossaries=glossaries, output_config=output_config, ) From 990be2ff965d9857f75600d023e865382fcbf102 Mon Sep 17 00:00:00 2001 From: Mike Ganbold Date: Thu, 27 Feb 2020 12:57:56 -0800 Subject: [PATCH 5/6] added link to supported file types & modified default values of input uri --- .../automl/translate_v3_batch_translate_text_with_model.py | 3 ++- translate/cloud-client/translate_v3_batch_translate_text.py | 3 ++- .../translate_v3_batch_translate_text_with_glossary.py | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/translate/automl/translate_v3_batch_translate_text_with_model.py b/translate/automl/translate_v3_batch_translate_text_with_model.py index e9307722c958..b97d8b7d8fa5 100644 --- a/translate/automl/translate_v3_batch_translate_text_with_model.py +++ b/translate/automl/translate_v3_batch_translate_text_with_model.py @@ -18,7 +18,7 @@ def batch_translate_text_with_model( - input_uri="gs://YOUR_BUCKET_ID/path/to/your/file.type", + input_uri="gs://YOUR_BUCKET_ID/path/to/your/file.txt", output_uri="gs://YOUR_BUCKET_ID/path/to/save/results/", project_id="YOUR_PROJECT_ID", model_id="YOUR_MODEL_ID", @@ -28,6 +28,7 @@ def batch_translate_text_with_model( client = translate.TranslationServiceClient() + # Supported file types: https://cloud.google.com/translate/docs/supported-formats gcs_source = {"input_uri": input_uri} location = "us-central1" diff --git a/translate/cloud-client/translate_v3_batch_translate_text.py b/translate/cloud-client/translate_v3_batch_translate_text.py index 37a5e97c144e..b4650e054b24 100644 --- a/translate/cloud-client/translate_v3_batch_translate_text.py +++ b/translate/cloud-client/translate_v3_batch_translate_text.py @@ -17,7 +17,7 @@ def batch_translate_text( - input_uri="gs://YOUR_BUCKET_ID/path/to/your/file.type", + input_uri="gs://YOUR_BUCKET_ID/path/to/your/file.txt", output_uri="gs://YOUR_BUCKET_ID/path/to/save/results/", project_id="YOUR_PROJECT_ID" ): @@ -26,6 +26,7 @@ def batch_translate_text( client = translate.TranslationServiceClient() location = "us-central1" + # Supported file types: https://cloud.google.com/translate/docs/supported-formats gcs_source = {"input_uri": input_uri} input_configs_element = { diff --git a/translate/cloud-client/translate_v3_batch_translate_text_with_glossary.py b/translate/cloud-client/translate_v3_batch_translate_text_with_glossary.py index 3b29da960567..fa08d641b5ec 100644 --- a/translate/cloud-client/translate_v3_batch_translate_text_with_glossary.py +++ b/translate/cloud-client/translate_v3_batch_translate_text_with_glossary.py @@ -18,7 +18,7 @@ def batch_translate_text_with_glossary( - input_uri="gs://YOUR_BUCKET_ID/path/to/your/file.type", + input_uri="gs://YOUR_BUCKET_ID/path/to/your/file.txt", output_uri="gs://YOUR_BUCKET_ID/path/to/save/results/", project_id="YOUR_PROJECT_ID", glossary_id="YOUR_GLOSSARY_ID", @@ -30,6 +30,8 @@ def batch_translate_text_with_glossary( # Supported language codes: https://cloud.google.com/translate/docs/languages location = "us-central1" + + # Supported file types: https://cloud.google.com/translate/docs/supported-formats gcs_source = {"input_uri": input_uri} input_configs_element = { From 89fb84985a13a231d09e70492f5d30c76b74b854 Mon Sep 17 00:00:00 2001 From: Mike Ganbold Date: Mon, 2 Mar 2020 14:13:56 -0800 Subject: [PATCH 6/6] fixed small nit --- .../automl/translate_v3_batch_translate_text_with_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/translate/automl/translate_v3_batch_translate_text_with_model.py b/translate/automl/translate_v3_batch_translate_text_with_model.py index b97d8b7d8fa5..010f7f93a90c 100644 --- a/translate/automl/translate_v3_batch_translate_text_with_model.py +++ b/translate/automl/translate_v3_batch_translate_text_with_model.py @@ -41,7 +41,7 @@ def batch_translate_text_with_model( parent = client.location_path(project_id, location) model_path = "projects/{}/locations/{}/models/{}".format( - project_id, "us-central1", model_id # The location of AutoML model. + project_id, location, model_id # The location of AutoML model. ) # Supported language codes: https://cloud.google.com/translate/docs/languages