Akhil Koduri commited on
Commit
a8c2f4b
1 Parent(s): c818c30

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -16
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": "German",
10
- "Eastern Panjabi": "Punjabi",
11
- "Sanskrit": "Sanskrit",
12
- "Urdu": "Urdu",
13
- "Tamil": "Tamil",
14
- "Telugu": "Telugu",
15
- "Yue Chinese": "Chinese",
16
- "Chinese (Simplified)": "Chinese",
17
- "Chinese (Traditional)": "Chinese",
18
- "Hindi": "Hindi",
19
- "French": "French",
20
- "Spanish": "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(translation_prompt)
 
 
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