|
import gradio as gr |
|
from transformers import pipeline |
|
|
|
|
|
|
|
lulu = pipeline("translation", model="tirtohadi/lulu-v1") |
|
|
|
|
|
def translate(text): |
|
|
|
paragraphs = text.split("\n\n") |
|
|
|
|
|
translated_paragraphs_lulu = [] |
|
|
|
for paragraph in paragraphs: |
|
|
|
|
|
|
|
|
|
translated_paragraph_lulu = lulu(paragraph, max_length=400)[0]["translation_text"] |
|
translated_paragraphs_lulu.append(translated_paragraph_lulu) |
|
|
|
|
|
|
|
translated_text_lulu = "\n\n".join(translated_paragraphs_lulu) |
|
|
|
|
|
return translated_text_lulu |
|
|
|
with gr.Blocks() as demo: |
|
gr.HTML("<h2>Lulu Translate</h2>") |
|
gr.Markdown("Lulu is a Christian domain specific machine translation") |
|
with gr.Row(): |
|
input_text1 = gr.Textbox(label="English Text",lines=5) |
|
output_lulu = gr.Textbox(label="Indonesian Translation",lines=5) |
|
|
|
with gr.Row(): |
|
with gr.Column(scale=1): |
|
btn = gr.Button("Translate") |
|
btn.click(fn=translate, inputs=input_text1, outputs=[output_lulu], api_name="translate") |
|
|
|
demo.launch() |