File size: 781 Bytes
4ca439a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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()