i'm trying to use this code i found online to translate images with Google Translate in bulk
# 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.
# """c
input_dir = "D:\e\homework\manga doujins and hentai\[Shuuki] Onechan ga wakan nai! 1"
output_dir = "D:\e\homework\manga doujins and hentai\[Shuuki] Onechan ga wakan nai! 1\\translated"
target_language = "french"
# Create a Google Translate client.
from google.cloud import translate
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)
but I keep getting the ModuleNotFoundError: No module named 'google' error
I wanted for each image to be uploaded to google translate, translate it to another language, downloaded the translated image, and do so for every other image in the directory
This is a warning on PyPi:
In your case, it appears you want to use the translate package, so you need to look at https://pypi.org/project/google-cloud-translate/. So create a venv and
pip install google-cloud-translatein your venv. Remember to use a supported python version asgoogle-cloud-translatecurrently requires Python >=3.7.