Spaces:
Sleeping
Sleeping
Thore Andresen
commited on
Commit
·
0f36f28
1
Parent(s):
51f4767
Use proper language names for language selection
Browse files
app.py
CHANGED
|
@@ -2,6 +2,13 @@ import gradio as gio
|
|
| 2 |
from inference import Translator
|
| 3 |
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
class TranslationInterface:
|
| 6 |
def __init__(self, languages, create_response) -> None:
|
| 7 |
self.interface = gio.Interface(
|
|
@@ -36,11 +43,13 @@ if __name__ == "__main__":
|
|
| 36 |
translator = Translator.from_pretrained('CmdCody/nllb-deu-moo')
|
| 37 |
|
| 38 |
def generate_translation(src_lang, tgt_lang, message):
|
| 39 |
-
result = translator.translate(message,
|
|
|
|
|
|
|
| 40 |
return result[0]
|
| 41 |
|
| 42 |
interface = TranslationInterface(
|
| 43 |
-
|
| 44 |
generate_translation
|
| 45 |
)
|
| 46 |
interface.launch()
|
|
|
|
| 2 |
from inference import Translator
|
| 3 |
|
| 4 |
|
| 5 |
+
LANGUAGES = {
|
| 6 |
+
"German": "deu_Latn",
|
| 7 |
+
"English": "eng_Latn",
|
| 8 |
+
"Danish": "dan_Latn",
|
| 9 |
+
"North Frisian (Mooring)": "moo_Latn"
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
class TranslationInterface:
|
| 13 |
def __init__(self, languages, create_response) -> None:
|
| 14 |
self.interface = gio.Interface(
|
|
|
|
| 43 |
translator = Translator.from_pretrained('CmdCody/nllb-deu-moo')
|
| 44 |
|
| 45 |
def generate_translation(src_lang, tgt_lang, message):
|
| 46 |
+
result = translator.translate(message,
|
| 47 |
+
src_lang=LANGUAGES[src_lang],
|
| 48 |
+
tgt_lang=LANGUAGES[tgt_lang])
|
| 49 |
return result[0]
|
| 50 |
|
| 51 |
interface = TranslationInterface(
|
| 52 |
+
list(LANGUAGES.keys()),
|
| 53 |
generate_translation
|
| 54 |
)
|
| 55 |
interface.launch()
|