File size: 837 Bytes
c35181d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from transformers import pipeline
import gradio as gr


# Alternatoive model
# Helsinki-NLP/opus-mt-en-tl



# the translator pipeline
translator = pipeline(
    "translation",
    model="kaiku03/open_subtitles-finetuned-opus-mt-en-tl-accelerate"
)


# function for the gradio app
def fn_translator(prompt):
    return translator(prompt)[0]['translation_text']


# gradio app
# Define example inputs and outputs
examples = [
    "your such an idiot",
    "lightning fast",
    "no one likes me",
]

iface = gr.Interface(
    fn=fn_translator,
    inputs='text',
    outputs=gr.Label(label="translation"),
    examples=[
        [ex] for ex in examples
    ],
    title='English to Tagalog translator',
    description='This demo performs language translation from English to Tagalog.',
    article='All done by Kaiku',
)

iface.launch()