Spaces:
Runtime error
Runtime error
update to use siswati-english models
Browse files
app.py
CHANGED
|
@@ -1,40 +1,33 @@
|
|
| 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, direction):
|
| 10 |
-
if direction == 'en->
|
| 11 |
-
|
| 12 |
else:
|
| 13 |
-
|
| 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 |
-
Multi-domain Translation Between
|
| 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,
|
|
@@ -42,11 +35,12 @@ iface = gr.Interface(
|
|
| 42 |
gr.inputs.Textbox(lines=5, placeholder="Enter text (maximum 5 lines)", label="Input"),
|
| 43 |
gr.inputs.Radio(
|
| 44 |
choices=[
|
| 45 |
-
'en->
|
| 46 |
-
'
|
| 47 |
-
default='en->
|
| 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_en_ss = pipeline("translation", model="dsfsi/en-ss-m2m100-combo")
|
| 5 |
+
translater_ss_en = pipeline("translation", model="dsfsi/ss-en-m2m100-combo")
|
| 6 |
|
| 7 |
def translate(inp, direction):
|
| 8 |
+
if direction == 'en->ss':
|
| 9 |
+
res = translater_en_ss(inp, max_length=512, early_stopping=True)[0]['translation_text']
|
| 10 |
else:
|
| 11 |
+
res = translater_ss_en(inp, max_length=512, early_stopping=True)[0]['translation_text']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
return res
|
| 13 |
|
| 14 |
description = """
|
| 15 |
<p>
|
| 16 |
<center>
|
| 17 |
+
Multi-domain Translation Between Siswati and English
|
| 18 |
</center>
|
| 19 |
</p>
|
| 20 |
"""
|
| 21 |
+
article = "<p style='text-align: center'><a href='https://huggingface.co/dsfsi/en-ss-m2m100-combo' target='_blank'>by dsfsi</a></p></center></p>"
|
| 22 |
+
|
| 23 |
examples = [
|
| 24 |
+
["Thank you for your help", "en->ss"],
|
| 25 |
+
["Ngiyabonga ngesiciniseko sakho", "ss->en"]
|
| 26 |
]
|
| 27 |
+
|
| 28 |
iface = gr.Interface(
|
| 29 |
fn=translate,
|
| 30 |
+
title="Siswati-English Translation",
|
|
|
|
| 31 |
description=description,
|
| 32 |
article=article,
|
| 33 |
examples=examples,
|
|
|
|
| 35 |
gr.inputs.Textbox(lines=5, placeholder="Enter text (maximum 5 lines)", label="Input"),
|
| 36 |
gr.inputs.Radio(
|
| 37 |
choices=[
|
| 38 |
+
'en->ss',
|
| 39 |
+
'ss->en'],
|
| 40 |
+
default='en->ss',
|
| 41 |
label='Direction'),
|
| 42 |
],
|
| 43 |
+
outputs="text"
|
| 44 |
+
)
|
| 45 |
|
| 46 |
+
iface.launch(enable_queue=True)
|