Skip to content
    Back to all Bounties

    Earn 27,000 ($270.00)

    Time Remainingdue 1 year ago
    In Progress

    OpenAI Multilingual Text Translator

    cbundy
    cbundy
    Posted 1 year ago

    Bounty Description

    Problem Description

    The purpose of this project is to create a Python-based application that leverages OpenAI's APIs to translate a large text block from one language to another chosen language. The input will be a text string, a chosen language, and the output will be the translated text. This will require elegantly breaking the long form text into segments to be processed iteratively.

    Acceptance Criteria

    Application will need to translate long form text (think chapters in a book).

    Technical Details

    Requirements:
    Python 3.8 or higher
    OpenAI Python Library (https://github.com/openai/openai)
    API Key for OpenAI API access (GPT4 API)
    Functional Requirements:
    The application shall accept input text and a list of target languages.
    The application shall connect to OpenAI's API to perform the translations.
    The application shall return the translated text for each target language.
    The application shall handle errors and exceptions gracefully.
    Non-Functional Requirements:
    The application should be modular, maintainable, and well-documented.
    The application should be efficient and minimize API usage to reduce costs.
    Specifications:
    Configuration:
    Store the OpenAI API key in an environment variable or configuration file.
    Modules:
    main.py: Main script to run the application.
    translator.py: Contains the Translator class and related functions.
    utils.py: Contains utility functions for handling user input and output.
    Classes and Functions:
    Translator class (translator.py):
    Attributes:
    api_key: The OpenAI API key.
    Methods:
    init(self, api_key: str): Constructor that initializes the Translator object with the provided API key.
    translate(self, text: str, target_languages: List[str]) -> Dict[str, str]: Accepts the input text and a list of target languages, connects to OpenAI's API, performs the translations, and returns a dictionary with the translated text for each target language. The dictionary keys will be the language codes and the values will be the translated texts.
    Utility functions (utils.py):
    validate_language_codes(languages: List[str]) -> List[str]: Validates the language codes provided by the user according to the supported languages by OpenAI API and returns a list of valid language codes.
    parse_input() -> Tuple[str, List[str]]: Accepts user input for the text to be translated and the target languages (comma-separated language codes). It returns a tuple containing the text and a list of target language codes.
    display_output(translations: Dict[str, str]): Accepts a dictionary containing translations and displays the output in a user-friendly format. The function iterates through the dictionary and prints the translated text for each target language in a readable format.
    Main script (main.py):
    Import necessary modules and functions from translator.py and utils.py.
    Call parse_input() function from utils.py to obtain user input for the text to be translated and the target languages (comma-separated language codes).
    Call validate_language_codes() function from utils.py with the list of target languages to validate and filter the language codes provided by the user.
    Create an instance of the Translator class from translator.py with the OpenAI API key, which should be stored in an environment variable or configuration file.
    Call the translate() method on the Translator instance with the input text and the list of valid target languages to get a dictionary containing the translations for each target language.
    Call display_output() function from utils.py with the dictionary of translations to display the output in a user-friendly format.
    Utility functions (utils.py):
    validate_language_codes(languages: List[str]) -> List[str]: Validates the language codes provided by the user and returns a list of valid language codes.
    parse_input() -> Tuple[str, List[str]]: Accepts user input for the text to be translated and the target languages, and returns a tuple containing the text and a list of target languages.
    display_output(translations: Dict[str, str]): Accepts a dictionary containing translations and displays the output in a user-friendly format.
    Main script (main.py):
    Import necessary modules and functions.
    Obtain user input for the text to be translated and the target languages.
    Validate the language codes provided by the user.
    Create an instance of the Translator class with the OpenAI API key.
    Call the translate method to get the translations for the target languages.
    Display the output in a user-friendly format.
    Testing:
    Perform unit testing for each function and method to ensure they work as expected.
    Test the application with various input texts and target languages to verify accurate translations.
    Test the application with edge cases and invalid inputs to ensure proper error handling and exception management.
    Documentation:
    Provide inline comments to explain the purpose and functionality of each module, class, and function.
    Create a README.md file to explain

    Copyright © 2024 Replit, Inc. All rights reserved.
    • twitter
    • tiktok
    • instagram
    • facebook

    Replit

    Programming languages

    • Python
    • JavaScript
    • TypeScript
    • Node.js
    • Nix
    • HTML, CSS, JS
    • C++
    • Golang