Spaces:
Sleeping
Sleeping
update model for ndebele-english translation
Browse files
app.py
CHANGED
@@ -1,52 +1,35 @@
|
|
1 |
import gradio as gr
|
2 |
-
from gradio.mix import Parallel, Series
|
3 |
-
|
4 |
from transformers import pipeline
|
5 |
|
6 |
-
|
7 |
-
|
8 |
|
9 |
-
def translate(inp
|
10 |
-
|
11 |
-
|
12 |
-
else:
|
13 |
-
text = "vi: " + inp
|
14 |
-
|
15 |
-
res = translater(
|
16 |
-
text,
|
17 |
-
max_length=512,
|
18 |
-
early_stopping=True,
|
19 |
-
)[0]['translation_text'][3:]
|
20 |
return res
|
21 |
|
22 |
description = """
|
23 |
<p>
|
24 |
<center>
|
25 |
-
|
26 |
</center>
|
27 |
</p>
|
28 |
"""
|
29 |
-
article = "<p style='text-align: center'><a href='
|
|
|
30 |
examples = [
|
31 |
-
["
|
32 |
-
["
|
33 |
]
|
|
|
34 |
iface = gr.Interface(
|
35 |
fn=translate,
|
36 |
-
|
37 |
-
title="🌸MTet Translation🌸",
|
38 |
description=description,
|
39 |
article=article,
|
40 |
examples=examples,
|
41 |
-
inputs=
|
42 |
-
|
43 |
-
|
44 |
-
choices=[
|
45 |
-
'en->vi',
|
46 |
-
'vi->en'],
|
47 |
-
default='en->vi',
|
48 |
-
label='Direction'),
|
49 |
-
],
|
50 |
-
outputs="text")
|
51 |
|
52 |
-
iface.launch(enable_queue=True)
|
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
translater_nr_en = pipeline("translation", model="dsfsi/nr-en-m2m100-gov", src_lang="nr", tgt_lang="en")
|
|
|
5 |
|
6 |
+
def translate(inp):
|
7 |
+
# Translate from isiNdebele to English
|
8 |
+
res = translater_nr_en(inp, max_length=512, early_stopping=True)[0]['translation_text']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
return res
|
10 |
|
11 |
description = """
|
12 |
<p>
|
13 |
<center>
|
14 |
+
One-way Translation from isiNdebele to English
|
15 |
</center>
|
16 |
</p>
|
17 |
"""
|
18 |
+
article = "<p style='text-align: center'><a href='https://huggingface.co/dsfsi/nr-en-m2m100-gov' target='_blank'>by dsfsi</a></p></center></p>"
|
19 |
+
|
20 |
examples = [
|
21 |
+
["Ngiyabonga kakhulu ngesipho osinike sona."],
|
22 |
+
["Ukuthula kuhlale kuyindlela ephilayo yempilo yethu."]
|
23 |
]
|
24 |
+
|
25 |
iface = gr.Interface(
|
26 |
fn=translate,
|
27 |
+
title="isiNdebele to English Translation",
|
|
|
28 |
description=description,
|
29 |
article=article,
|
30 |
examples=examples,
|
31 |
+
inputs=gr.components.Textbox(lines=5, placeholder="Enter isiNdebele text (maximum 5 lines)", label="Input"),
|
32 |
+
outputs="text"
|
33 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
+
iface.launch(enable_queue=True)
|