ISE-1 / translator.py
AliArshad's picture
Update translator.py
7274f48
raw
history blame contribute delete
808 Bytes
import gradio as gr
from transformers import pipeline
# Create a translation pipeline for English to French
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-fr")
def translate(text):
translated_text = translator(text, max_length=40)[0]["translation_text"]
return translated_text
with gr.Blocks() as demo:
with gr.Row():
with gr.Column():
english = gr.Textbox(label="English text")
translate_btn = gr.Button(value="Translate")
with gr.Column():
french = gr.Textbox(label="French Text")
translate_btn.click(translate, inputs=english, outputs=french, api_name="translate-to-french")
examples = gr.Examples(examples=["I went to the supermarket yesterday.", "Helen is a good swimmer."], inputs=english)
demo.launch()