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

  1. Replace access_key and secret_key with your AWS Access Key ID and Secret Access Key.

  2. Set the user_input variable to the JSON data you want to convert.

  3. Set the language variable to the target language for conversion.

  4. Run the script using Python:

     python file_name.py
    
  5. 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:

  1. Create a text file test.txt with the following content:

     Hello, world! This is a test.
    
  2. Run the script and enter the target language when prompted (e.g., French).

  3. 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!!!