Update app.py
Browse files
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 |
-
|
| 66 |
-
model_path = Path("/code/models") /
|
| 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/{
|
| 72 |
-
output_dir=Path("/code/models") /
|
| 73 |
)
|
| 74 |
-
print(f"Loading model {
|
| 75 |
# Auto-detects GPU, set to "cpu" to force CPU inference
|
| 76 |
-
|
| 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 |
-
|
|
|
|
|
|
|
| 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):
|