Translation Automation using Amazon Bedrock 👨💻
Introduction
I have created a sample Python application that uses Amazon bedrock to showcase how you can automate your texts, JSON, API responses, text files, etc using Amazon bedrock.
Please enter the text to convert: Hello, world!
Please enter in which language you want to convert: French
Converted result response:
Bonjour, le monde !
Configuration
you can customize the scripts by modifying the following parameters in the code:
access_key
: Your AWS Access Key ID.secret_key
: Your AWS Secret Access Key.service
: The AWS service name (Bedrock in this case).url
: The Bedrock service endpoint URL.user_input
: The JSON data you want to convert.language
: The target language for conversion.
Note: make sure to install the latest version of boto3 to support bedrock or install the boto3 and boto-core libraries using the .tar.gz files present in bedrock-python-sdk.
Source Code
Check out my GitHub repository!!!
Usage
Replace
access_key
andsecret_key
with your AWS Access Key ID and Secret Access Key.Set the
user_input
variable to the JSON data you want to convert.Set the
language
variable to the target language for conversion.Run the script using Python:
python file_name.py
The script will send a request to the Bedrock service and display the converted JSON data.
Examples
Here's an example of how to use the text_translate script:
Please enter the text to convert: Hello, world!
Please enter in which language you want to convert: French
Converted result response:
Bonjour, le monde !
Here's an example of how to use the json_translate script:
Please enter the JSON to convert:
{
"headline": "Business Management System",
"user_initial": "G",
"name": "Himanshu"
}
Please enter in which language you want to convert: French
Converted result response:
{
"headline": "Système de gestion des affaires",
"user_initial": "G",
"name": "Himanshu"
}
Here's an example of how to use the script:
Create a text file
test.txt
with the following content:Hello, world! This is a test.
Run the script and enter the target language when prompted (e.g., French).
The script will display the converted text:
Bonjour, le monde ! Ceci est un test.
This is my first blog. I hope readers like it and this code will help someone. Please share your response on how I can improve and what you liked the most!!!