|
from transformers import pipeline |
|
import gradio as gr |
|
|
|
|
|
|
|
translator_en_to_ar = pipeline("text2text-generation", model="BoghdadyJR/en-ar-model") |
|
translator_ar_to_en = pipeline("text2text-generation", model="BoghdadyJR/ar-en-model") |
|
|
|
def translate(text, direction): |
|
if direction == "en_to_ar": |
|
return translator_en_to_ar(text)[0]['generated_text'] |
|
else: |
|
return translator_ar_to_en(text)[0]['generated_text'] |
|
|
|
|
|
def translate_text(text, direction): |
|
return translate(text, direction) |
|
|
|
|
|
iface = gr.Interface( |
|
fn=translate_text, |
|
inputs=[ |
|
gr.Textbox(lines=2, placeholder="Enter text here..."), |
|
gr.Radio(choices=["en_to_ar", "ar_to_en"], label="Translation Direction", value="en_to_ar") |
|
], |
|
outputs="text", |
|
title="Translation" |
|
) |
|
|
|
|
|
iface.launch() |