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( """
This space provides a bidirectional translation service from Siswati to English.
""" ) 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( """ """ ) with gr.Column(scale=1): pass with gr.Accordion("More Information", open=False): gr.Markdown("""