TiberiuCristianLeon commited on
Commit
b6635f5
·
verified ·
1 Parent(s): d035ef4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -62,21 +62,23 @@ class Translators:
62
  from quickmt import Translator
63
  from quickmt.hub import hf_download, hf_list
64
  from pathlib import Path
65
- input_model = f"quickmt-{self.sl}-{self.tl}"
66
- model_path = Path("/code/models") / input_model
67
  choices = [i.split("/")[1] for i in hf_list()]
68
  print(choices)
69
  if not model_path.exists():
70
  hf_download(
71
- model_name = f"quickmt/{input_model}",
72
- output_dir=Path("/code/models") / input_model,
73
  )
74
- print(f"Loading model {input_model}")
75
  # Auto-detects GPU, set to "cpu" to force CPU inference
76
- translation = Translator(str(model_path), device="auto", inter_threads=2)
77
  # translation = Translator(f"./quickmt-{self.sl}-{self.tl}/", device="auto", inter_threads=2)
78
  # Translate - set beam size to 1 for faster speed (but lower quality)
79
- return translation({self.input_text}, beam_size=5)
 
 
80
 
81
  @classmethod
82
  def download_argos_model(cls, from_code, to_code):
 
62
  from quickmt import Translator
63
  from quickmt.hub import hf_download, hf_list
64
  from pathlib import Path
65
+ model_name = f"quickmt-{self.sl}-{self.tl}"
66
+ model_path = Path("/code/models") / model_name
67
  choices = [i.split("/")[1] for i in hf_list()]
68
  print(choices)
69
  if not model_path.exists():
70
  hf_download(
71
+ model_name = f"quickmt/{model_name}",
72
+ output_dir=Path("/code/models") / model_name,
73
  )
74
+ print(f"Loading model {model_name}")
75
  # Auto-detects GPU, set to "cpu" to force CPU inference
76
+ translator = Translator(str(model_path), device="auto", inter_threads=2)
77
  # translation = Translator(f"./quickmt-{self.sl}-{self.tl}/", device="auto", inter_threads=2)
78
  # Translate - set beam size to 1 for faster speed (but lower quality)
79
+ translation = translator({self.input_text}, beam_size=5)
80
+ message = f'Translated from {iso1_to_name[self.sl]} to {iso1_to_name[self.tl]} with {model_name}.'
81
+ return translation, message
82
 
83
  @classmethod
84
  def download_argos_model(cls, from_code, to_code):