Initial commit
Browse files
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import translation_direction_detection as tdd
|
2 |
+
from nmtscore import NMTScorer
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
detector = tdd.TranslationDirectionDetector(NMTScorer("m2m100_418M"))
|
6 |
+
|
7 |
+
def translate_direction(text1, lang1, text2, lang2):
|
8 |
+
lang_to_code = {"English": 'en',
|
9 |
+
"German": 'de',
|
10 |
+
"French": 'fr',
|
11 |
+
"Czech": 'cs',
|
12 |
+
"Ukrainian": 'uk',
|
13 |
+
"Chinese": 'zh',
|
14 |
+
"Russian": 'ru',
|
15 |
+
"Bengali": 'bn',
|
16 |
+
"Hindi": 'hi',
|
17 |
+
"Xhosa": 'xh',
|
18 |
+
"Zulu": 'zu',
|
19 |
+
}
|
20 |
+
if "\n" in text1 or "\n" in text2:
|
21 |
+
sentence1 = text1.split("\n")
|
22 |
+
sentence2 = text2.split("\n")
|
23 |
+
else:
|
24 |
+
sentence1 = text1
|
25 |
+
sentence2 = text2
|
26 |
+
result = detector.detect(sentence1, sentence2, lang_to_code[lang1], lang_to_code[lang2])
|
27 |
+
return result
|
28 |
+
|
29 |
+
iface = gr.Interface(
|
30 |
+
fn=translate_direction,
|
31 |
+
inputs=[
|
32 |
+
gr.Textbox(placeholder="Enter a single sentence or multiple sentences separated by a line break (Shift+Enter) in language 1 here.", label="Text 1"),
|
33 |
+
gr.Dropdown(choices=["English", "German", "French", "Czech", "Ukranian", "Chinese", "Russian", "Bengali", "Hindi", "Xhosa", "Zulu"], label="Language of Text 1"),
|
34 |
+
gr.Textbox(placeholder="Enter a single sentence or multiple sentences separated by a line break (Shift+Enter) in language 2 here.", label="Text 2"),
|
35 |
+
gr.Dropdown(choices=["English", "German", "French", "Czech", "Ukranian", "Chinese", "Russian", "Bengali", "Hindi", "Xhosa", "Zulu"], label="Language of Text 2")
|
36 |
+
],
|
37 |
+
outputs=gr.Textbox(label="Result"),
|
38 |
+
title="Translation Direction Detector",
|
39 |
+
description="Detects the translation direction between two sentences using the M2M100 418M translation model.",
|
40 |
+
theme="dark"
|
41 |
+
)
|
42 |
+
|
43 |
+
iface.launch()
|