Spaces:
Sleeping
Sleeping
File size: 1,347 Bytes
3d4f13a 9bb8977 1335053 2df477a 353fb7a 2df477a 3d4f13a 1335053 2df477a 1335053 2df477a 1335053 2df477a 1335053 2df477a 1335053 2df477a 1335053 db7cd29 7ac95a7 2df477a 1335053 2df477a 1335053 2df477a 7ac95a7 db7cd29 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
import gradio as gr
from transformers import pipeline
translater_en_ss = pipeline("translation", model="dsfsi/en-ss-m2m100-combo", src_lang="en", tgt_lang="ss")
translater_ss_en = pipeline("translation", model="dsfsi/ss-en-m2m100-combo", src_lang="ss", tgt_lang="en")
def translate(inp, direction):
if direction == 'en->ss':
res = translater_en_ss(inp, max_length=512, early_stopping=True)[0]['translation_text']
else:
res = translater_ss_en(inp, max_length=512, early_stopping=True)[0]['translation_text']
return res
description = """
<p>
<center>
Multi-domain Translation Between Siswati and English
</center>
</p>
"""
article = "<p style='text-align: center'><a href='https://huggingface.co/dsfsi/en-ss-m2m100-combo' target='_blank'>by dsfsi</a></p></center></p>"
examples = [
["Thank you for your help", "en->ss"],
["Ngiyabonga ngesiciniseko sakho", "ss->en"]
]
iface = gr.Interface(
fn=translate,
title="Siswati-English Translation",
description=description,
article=article,
examples=examples,
inputs=[
gr.Textbox(lines=5, placeholder="Enter text (maximum 5 lines)", label="Input"),
gr.Radio(
choices=['en->ss', 'ss->en'],
default='en->ss',
label='Direction'),
],
outputs="text"
)
iface.launch(enable_queue=True)
|