Spaces:
Sleeping
Sleeping
File size: 2,659 Bytes
3d4f13a 9bb8977 1335053 2df477a 353fb7a 2df477a 3d4f13a 99700a7 2df477a 99700a7 7ac95a7 99700a7 db7cd29 99700a7 |
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
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
with gr.Blocks() as demo:
with gr.Row():
with gr.Column(scale=1):
pass
with gr.Column(scale=4, min_width=1000):
gr.Image("logo_transparent_small.png", elem_id="logo", show_label=False, width=500)
gr.Markdown(
"""
<h1 style='text-align: center;'>Siswati-English Translation</h1>
<p style='text-align: center;'>This space provides a bidirectional translation service from Siswati to English.</p>
"""
)
with gr.Column(scale=1):
pass
with gr.Row():
with gr.Column(scale=1):
pass
with gr.Column(scale=4, min_width=1000):
inp_text = gr.Textbox(lines=5, placeholder="Enter text (maximum 5 lines)", label="Input")
direction = gr.Radio(choices=['en->ss', 'ss->en'], label='Direction')
translate_button = gr.Button("Translate")
output_text = gr.Textbox(label="Output")
translate_button.click(translate, inputs=[inp_text, direction], outputs=output_text)
with gr.Column(scale=1):
pass
with gr.Row():
with gr.Column(scale=1):
pass
with gr.Column(scale=4, min_width=1000):
gr.Markdown(
"""
<div style='text-align: center;'>
<a href='https://github.com/dsfsi/en-ss-m2m100-combo' target='_blank'>En-Ss GitHub</a> |
<a href='https://github.com/dsfsi/ss-en-m2m100-combo' target='_blank'>Ss-En GitHub</a> |
<a href='https://docs.google.com/forms/d/e/1FAIpQLSf7S36dyAUPx2egmXbFpnTBuzoRulhL5Elu-N1eoMhaO7v10w/viewform' target='_blank'>Feedback Form</a>
</div>
"""
)
with gr.Column(scale=1):
pass
with gr.Accordion("More Information", open=False):
gr.Markdown("""
<h4 style="text-align: center;">Authors</h4>
<div style='text-align: center;'>Vukosi Marivate, Richard Lastrucci</div>
""")
demo.launch()
|