Update app.py
Browse files
app.py
CHANGED
|
@@ -66,8 +66,8 @@ class Translators:
|
|
| 66 |
translator = Translator(str(model_path), device = device)
|
| 67 |
# translation = Translator(f"./quickmt-{self.sl}-{self.tl}/", device="auto", inter_threads=2)
|
| 68 |
# set beam size to 1 for faster speed (but lower quality)
|
| 69 |
-
translation = translator(input_text, beam_size=5)
|
| 70 |
-
print(model_path, input_text, translation)
|
| 71 |
return translation
|
| 72 |
|
| 73 |
@staticmethod
|
|
@@ -96,6 +96,7 @@ class Translators:
|
|
| 96 |
# available_languages.sort()
|
| 97 |
available_languages = ['ar', 'bn', 'cs', 'da', 'de', 'el', 'en', 'es', 'fa', 'fr', 'he', 'hi', 'hu',
|
| 98 |
'id', 'it', 'ja', 'ko', 'lv', 'pl', 'pt', 'ro', 'ru', 'th', 'tr', 'ur', 'vi', 'zh']
|
|
|
|
| 99 |
if f"{self.sl}-{self.tl}" in quickmt_models:
|
| 100 |
model_path = Translators.quickmtdownload(model_name)
|
| 101 |
translation = Translators.quickmttranslate(model_path, self.input_text)
|
|
@@ -109,7 +110,7 @@ class Translators:
|
|
| 109 |
model_path = Translators.quickmtdownload(model_name)
|
| 110 |
translation = Translators.quickmttranslate(model_path, entranslation)
|
| 111 |
message = f'Translated from {iso1_to_name[self.sl]} to {iso1_to_name[self.tl]} with pivot language English.'
|
| 112 |
-
else:
|
| 113 |
translation = f'Model {model_name} from {iso1_to_name[self.sl]} to {iso1_to_name[self.tl]} not available!'
|
| 114 |
message = f"Available models: {', '.join(quickmt_models)}"
|
| 115 |
return translation, message
|
|
|
|
| 66 |
translator = Translator(str(model_path), device = device)
|
| 67 |
# translation = Translator(f"./quickmt-{self.sl}-{self.tl}/", device="auto", inter_threads=2)
|
| 68 |
# set beam size to 1 for faster speed (but lower quality)
|
| 69 |
+
translation = translator(input_text, beam_size=5, compute_type="float16")
|
| 70 |
+
# print(model_path, input_text, translation)
|
| 71 |
return translation
|
| 72 |
|
| 73 |
@staticmethod
|
|
|
|
| 96 |
# available_languages.sort()
|
| 97 |
available_languages = ['ar', 'bn', 'cs', 'da', 'de', 'el', 'en', 'es', 'fa', 'fr', 'he', 'hi', 'hu',
|
| 98 |
'id', 'it', 'ja', 'ko', 'lv', 'pl', 'pt', 'ro', 'ru', 'th', 'tr', 'ur', 'vi', 'zh']
|
| 99 |
+
# Direct translation model
|
| 100 |
if f"{self.sl}-{self.tl}" in quickmt_models:
|
| 101 |
model_path = Translators.quickmtdownload(model_name)
|
| 102 |
translation = Translators.quickmttranslate(model_path, self.input_text)
|
|
|
|
| 110 |
model_path = Translators.quickmtdownload(model_name)
|
| 111 |
translation = Translators.quickmttranslate(model_path, entranslation)
|
| 112 |
message = f'Translated from {iso1_to_name[self.sl]} to {iso1_to_name[self.tl]} with pivot language English.'
|
| 113 |
+
else:
|
| 114 |
translation = f'Model {model_name} from {iso1_to_name[self.sl]} to {iso1_to_name[self.tl]} not available!'
|
| 115 |
message = f"Available models: {', '.join(quickmt_models)}"
|
| 116 |
return translation, message
|