Fil*_*tio 1 python translation google-cloud-platform
这是我第一次运行谷歌批量翻译,我通常运行API翻译,但这次我的文件太大,无法以这种方式翻译。
我尝试运行以下脚本,但收到下面的权限错误,我不知道如何继续。任何帮助深表感谢..
from google.cloud import translate
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]= r"C:\Users\..my_path..\cred.json"
# translate_client = translate.Client()
def batch_translate_text(
input_uri="gs://....",
output_uri="gs://....",
project_id="....",
timeout=180):
"""Translates a batch of texts on GCS and stores the result in a GCS location."""
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 = {
"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 = f"projects/{project_id}/locations/{location}"
# Supported language codes: https://cloud.google.com/translate/docs/language
operation = client.batch_translate_text(
request={
"parent": parent,
"source_language_code": "zh-CN",
"target_language_codes": ["en"], # Up to 10 language codes here.
"input_configs": [input_configs_element],
"output_config": output_config,
}
)
print("Waiting for operation to complete...")
response = operation.result(timeout)
print("Total Characters: {}".format(response.total_characters))
print("Translated Characters: {}".format(response.translated_characters))
batch_translate_text()
Run Code Online (Sandbox Code Playgroud)
PermissionDenied:403 Cloud IAM 权限“cloudtranslate.generalModels.batchPredict”被拒绝。
| 归档时间: |
|
| 查看次数: |
4487 次 |
| 最近记录: |