TiberiuCristianLeon commited on
Commit
e5ffc74
·
verified ·
1 Parent(s): aead9b1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -4
app.py CHANGED
@@ -93,7 +93,6 @@ class Translators:
93
  translated_text = f"No Argos model for {self.sl} to {self.tl}. Try other model or languages combination from the available Argos models: {packages_info}."
94
  except Exception as error:
95
  translated_text = error
96
- print(error)
97
  return translated_text
98
 
99
  def HelsinkiNLP(self):
@@ -114,7 +113,7 @@ class Translators:
114
  pipe = pipeline("translation", model=model_name)
115
  non_empty_iso = df.slice(1).filter(pl.col("ISO639-1") != "").rows()
116
  iso1_dict = {iso[1]: (iso[0], iso[2], iso[3]) for iso in non_empty_iso}
117
- iso3tl = iso1_dict.get(self.tl)[2] # 'deu'
118
  translation = pipe(f'>>{iso3tl}<< {self.input_text}')
119
  return translation[0]['translation_text'], f'Translated from {self.sl} to {self.tl} with {model_name}.'
120
  except Exception as error:
@@ -267,7 +266,7 @@ class Translators:
267
  inputs = tokenizer(prompt, return_tensors="pt")
268
  outputs = model.generate(**inputs, max_new_tokens=512)
269
  output = tokenizer.decode(outputs[0], skip_special_tokens=True)
270
- result = output.rsplit(f'{self.tl}:')[-1].strip() if '\n' in output else output.strip()
271
  return result
272
 
273
  def eurollm_instruct(self):
@@ -355,7 +354,6 @@ def translate_text(input_text: str, s_language: str, t_language: str, model_name
355
  sl = all_langs[s_language]
356
  tl = all_langs[t_language]
357
  message_text = f'Translated from {s_language} to {t_language} with {model_name}'
358
- print(message_text)
359
  try:
360
  if model_name.startswith("Helsinki-NLP"):
361
  translated_text, message_text = Translators(model_name, sl, tl, input_text).HelsinkiNLP()
 
93
  translated_text = f"No Argos model for {self.sl} to {self.tl}. Try other model or languages combination from the available Argos models: {packages_info}."
94
  except Exception as error:
95
  translated_text = error
 
96
  return translated_text
97
 
98
  def HelsinkiNLP(self):
 
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}.'
119
  except Exception as error:
 
266
  inputs = tokenizer(prompt, return_tensors="pt")
267
  outputs = model.generate(**inputs, max_new_tokens=512)
268
  output = tokenizer.decode(outputs[0], skip_special_tokens=True)
269
+ result = output.rsplit(f'{self.tl}:')[-1].strip() if '\n' in output or f'{self.tl}:' in output else output.strip()
270
  return result
271
 
272
  def eurollm_instruct(self):
 
354
  sl = all_langs[s_language]
355
  tl = all_langs[t_language]
356
  message_text = f'Translated from {s_language} to {t_language} with {model_name}'
 
357
  try:
358
  if model_name.startswith("Helsinki-NLP"):
359
  translated_text, message_text = Translators(model_name, sl, tl, input_text).HelsinkiNLP()