Spaces:
Sleeping
Sleeping
Akhil Koduri
commited on
Commit
•
a8c2f4b
1
Parent(s):
c818c30
Update app.py
Browse files
app.py
CHANGED
@@ -6,18 +6,18 @@ text_translator = pipeline("translation", model="facebook/nllb-200-distilled-600
|
|
6 |
|
7 |
# Dictionary mapping destination languages to their FLORES-200 codes
|
8 |
language_mapping = {
|
9 |
-
"German": "
|
10 |
-
"Eastern Panjabi": "
|
11 |
-
"Sanskrit": "
|
12 |
-
"Urdu": "
|
13 |
-
"Tamil": "
|
14 |
-
"Telugu": "
|
15 |
-
"Yue Chinese": "
|
16 |
-
"Chinese (Simplified)": "
|
17 |
-
"Chinese (Traditional)": "
|
18 |
-
"Hindi": "
|
19 |
-
"French": "
|
20 |
-
"Spanish": "
|
21 |
}
|
22 |
|
23 |
def translate_text(text, destination_language):
|
@@ -37,11 +37,10 @@ def translate_text(text, destination_language):
|
|
37 |
return "Unsupported language selected. Please choose a valid language."
|
38 |
|
39 |
try:
|
40 |
-
# Format translation prompt for T5 model
|
41 |
-
translation_prompt = f"translate English to {dest_code}: {text}"
|
42 |
-
|
43 |
# Perform translation using T5 model pipeline
|
44 |
-
translation = text_translator(
|
|
|
|
|
45 |
translated_text = translation[0]["translation_text"]
|
46 |
|
47 |
# Optionally return confidence score
|
|
|
6 |
|
7 |
# Dictionary mapping destination languages to their FLORES-200 codes
|
8 |
language_mapping = {
|
9 |
+
"German": "de_DE",
|
10 |
+
"Eastern Panjabi": "pa_IN",
|
11 |
+
"Sanskrit": "sa_IN",
|
12 |
+
"Urdu": "ur",
|
13 |
+
"Tamil": "ta",
|
14 |
+
"Telugu": "te",
|
15 |
+
"Yue Chinese": "zh_yue",
|
16 |
+
"Chinese (Simplified)": "zh",
|
17 |
+
"Chinese (Traditional)": "zh",
|
18 |
+
"Hindi": "hi",
|
19 |
+
"French": "fr",
|
20 |
+
"Spanish": "es"
|
21 |
}
|
22 |
|
23 |
def translate_text(text, destination_language):
|
|
|
37 |
return "Unsupported language selected. Please choose a valid language."
|
38 |
|
39 |
try:
|
|
|
|
|
|
|
40 |
# Perform translation using T5 model pipeline
|
41 |
+
translation = text_translator(text,
|
42 |
+
src_lang="en",
|
43 |
+
tgt_lang=dest_code)
|
44 |
translated_text = translation[0]["translation_text"]
|
45 |
|
46 |
# Optionally return confidence score
|