-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from BibleNLP/add-translation-in
Add translation in
- Loading branch information
Showing
9 changed files
with
114 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"""Translating the user's input to English using AWS Translate service""" | ||
|
||
import json | ||
|
||
import boto3 | ||
|
||
with open("../iso639-1.json", "r", encoding="utf-8") as f: | ||
iso_639_1 = json.load(f) | ||
|
||
|
||
def translate_text(text: str): | ||
""" | ||
Translates the given text to English using AWS Translate service | ||
:param text: The text to translate | ||
:return: The response, including the translated text | ||
""" | ||
translate = boto3.client(service_name="translate", use_ssl=True) | ||
|
||
# Call AWS Translate | ||
response = translate.translate_text( | ||
Text=text, | ||
SourceLanguageCode="auto", # Automatically detect the source language | ||
TargetLanguageCode="en", # Target language code is 'en' for English | ||
) | ||
|
||
source_language_code = response.get("SourceLanguageCode", "").split("-")[ | ||
0 | ||
] # Extracting ISO 639-1 code part | ||
response["language"] = iso_639_1.get(source_language_code, "Unknown language") | ||
|
||
return response | ||
|
||
|
||
if __name__ == "__main__": | ||
# Example text to translate | ||
TEST_TEXT = "Hola, mundo" | ||
# Call the translate_text function | ||
result = translate_text(TEST_TEXT) | ||
# Print the result | ||
print(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"en": "English", | ||
"fr": "French", | ||
"es": "Spanish", | ||
"de": "German", | ||
"it": "Italian", | ||
"pt": "Portuguese", | ||
"ar": "Arabic", | ||
"zh": "Chinese", | ||
"ja": "Japanese", | ||
"ko": "Korean", | ||
"ru": "Russian", | ||
"hi": "Hindi", | ||
"bn": "Bengali", | ||
"ur": "Urdu", | ||
"fa": "Persian", | ||
"tr": "Turkish", | ||
"th": "Thai", | ||
"id": "Indonesian", | ||
"ms": "Malay", | ||
"vi": "Vietnamese", | ||
"sw": "Swahili", | ||
"ha": "Hausa", | ||
"yo": "Yoruba" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ pgvector==0.1.8 | |
supabase==1.0.3 | ||
duckdb==0.7.1 | ||
tiktoken==0.5.1 | ||
boto3==1.34.46 |