TiberiuCristianLeon commited on
Commit
4045d37
·
verified ·
1 Parent(s): a64284b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -8,12 +8,15 @@ import polars as pl
8
 
9
  logging.set_verbosity_error()
10
  favourite_langs = {"German": "de", "Romanian": "ro", "English": "en", "-----": "-----"}
11
- all_langs = languagecodes.iso_languages
12
  df = pl.read_parquet("isolanguages.parquet")
 
 
 
13
 
14
  # Language options as list, add favourite languages first
15
  options = list(favourite_langs.keys())
16
  options.extend(list(all_langs.keys()))
 
17
  models = ["Helsinki-NLP",
18
  "facebook/nllb-200-distilled-600M", "facebook/nllb-200-distilled-1.3B", "facebook/nllb-200-1.3B", "facebook/nllb-200-3.3B",
19
  "facebook/mbart-large-50-many-to-many-mmt", "facebook/mbart-large-50-one-to-many-mmt", "facebook/mbart-large-50-many-to-one-mmt",
@@ -110,9 +113,8 @@ class Translators:
110
  except EnvironmentError as error:
111
  try: # Last resort: multi to multi
112
  model_name = "Helsinki-NLP/opus-mt-tc-bible-big-mul-mul"
113
- pipe = pipeline("translation", model=model_name)
114
- non_empty_iso = df.slice(1).filter(pl.col("ISO639-1") != "").rows()
115
- iso1_dict = {iso[1]: (iso[0], iso[2], iso[3]) for iso in non_empty_iso}
116
  iso3tl = iso1_dict.get(self.tl)[2] # 'deu', 'ron', 'eng', 'fra'
117
  translation = pipe(f'>>{iso3tl}<< {self.input_text}')
118
  return translation[0]['translation_text'], f'Translated from {self.sl} to {self.tl} with {model_name}.'
@@ -353,8 +355,8 @@ def translate_text(input_text: str, s_language: str, t_language: str, model_name
353
  ("Hallo Welt", "Translated from English to German with Helsinki-NLP.")
354
  """
355
 
356
- sl = all_langs[s_language]
357
- tl = all_langs[t_language]
358
  message_text = f'Translated from {s_language} to {t_language} with {model_name}'
359
  try:
360
  if model_name.startswith("Helsinki-NLP"):
 
8
 
9
  logging.set_verbosity_error()
10
  favourite_langs = {"German": "de", "Romanian": "ro", "English": "en", "-----": "-----"}
 
11
  df = pl.read_parquet("isolanguages.parquet")
12
+ non_empty_isos = df.slice(1).filter(pl.col("ISO639-1") != "").rows()
13
+ # all_langs = languagecodes.iso_languages
14
+ all_langs = {iso[0]: (iso[1], iso[2], iso[3]) for iso in non_empty_isos}
15
 
16
  # Language options as list, add favourite languages first
17
  options = list(favourite_langs.keys())
18
  options.extend(list(all_langs.keys()))
19
+
20
  models = ["Helsinki-NLP",
21
  "facebook/nllb-200-distilled-600M", "facebook/nllb-200-distilled-1.3B", "facebook/nllb-200-1.3B", "facebook/nllb-200-3.3B",
22
  "facebook/mbart-large-50-many-to-many-mmt", "facebook/mbart-large-50-one-to-many-mmt", "facebook/mbart-large-50-many-to-one-mmt",
 
113
  except EnvironmentError as error:
114
  try: # Last resort: multi to multi
115
  model_name = "Helsinki-NLP/opus-mt-tc-bible-big-mul-mul"
116
+ pipe = pipeline("translation", model=model_name)
117
+ iso1_dict = {iso[1]: (iso[0], iso[2], iso[3]) for iso in non_empty_isos}
 
118
  iso3tl = iso1_dict.get(self.tl)[2] # 'deu', 'ron', 'eng', 'fra'
119
  translation = pipe(f'>>{iso3tl}<< {self.input_text}')
120
  return translation[0]['translation_text'], f'Translated from {self.sl} to {self.tl} with {model_name}.'
 
355
  ("Hallo Welt", "Translated from English to German with Helsinki-NLP.")
356
  """
357
 
358
+ sl = all_langs[s_language][0]
359
+ tl = all_langs[t_language][0]
360
  message_text = f'Translated from {s_language} to {t_language} with {model_name}'
361
  try:
362
  if model_name.startswith("Helsinki-NLP"):