Перевод не обязательно должен быть безупречным, он уже достаточно, если это просто черная полоса поверх изображения с английским переводом.
Я наткнулся на другой пост, в котором был тот же вопрос, что и у меня, но решение в этом посте не сработало.
Идея заключалась в том, чтобы использовать библиотеку google-cloud-translate и небольшой скрипт Python, который преобразует изображения. Код был следующий:
Код: Выделить всё
import os
from google.cloud import translate_v2 as translate
def upload_and_translate(input_dir, output_dir, target_language):
"""Uploads all images in a directory, translates them using Google Translate, and downloads the translated images to a specified output directory.
Args:
input_dir: The directory containing the images to be translated.
output_dir: The directory to which the translated images will be downloaded.
target_language: The target language for the translation.
"""
# Create a Google Translate client.
client = translate.Client()
# Get a list of all the files in the input directory.
files = os.listdir(input_dir)
# Iterate over the files and upload them to Google Translate.
for file in files:
with open(os.path.join(input_dir, file), "rb") as f:
# Upload the image to Google Translate.
response = client.translate_image(
f,
target_language=target_language,
)
# Download the translated image.
with open(os.path.join(output_dir, file), "wb") as f:
f.write(response.translated_image)
# Example usage:
if __name__ == "__main__":
input_dir = "path/to/input/directory"
output_dir = "path/to/output/directory"
target_language = "es"
upload_and_translate(input_dir, output_dir, target_language)
Код: Выделить всё
raise exceptions.DefaultCredentialsError(_CLOUD_SDK_MISSING_CREDENTIALS)
google.auth.exceptions.DefaultCredentialsError: Your default credentials were not found. To set up Application Default Credentials, see https://cloud.google.com/docs/authentication/external/set-up-adc for more information.
Если кто-нибудь может дать краткое пошаговое руководство, я был бы очень признателен.
Подробнее здесь: https://stackoverflow.com/questions/786 ... ate-images