Spaces:
Sleeping
Sleeping
import gradio as gr | |
from transformers import pipeline | |
# Initialize the translation pipelines | |
translator_en_fi = pipeline("translation", model="Helsinki-NLP/opus-mt-en-fi") | |
translator_fi_en = pipeline("translation", model="Helsinki-NLP/opus-mt-fi-en") | |
def translate(text, direction): | |
if direction == 'en-fi': | |
result = translator_en_fi(text)[0]['translation_text'] | |
else: | |
result = translator_fi_en(text)[0]['translation_text'] | |
return result | |
iface = gr.Interface( | |
fn=translate, | |
inputs=[gr.inputs.Textbox(lines=2, placeholder="Enter text here..."), gr.inputs.Radio(["en-fi", "fi-en"])], | |
outputs="text", | |
title="Translation App", | |
description="Translate text between English and Finnish using Hugging Face Transformers." | |
) | |
iface.launch() |