Spaces:
Sleeping
Sleeping
alyxx
commited on
Commit
•
c35181d
1
Parent(s):
51316bc
added requirements and app.py
Browse files- app.py +42 -0
- requirements.txt +5 -0
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
|
5 |
+
# Alternatoive model
|
6 |
+
# Helsinki-NLP/opus-mt-en-tl
|
7 |
+
|
8 |
+
|
9 |
+
|
10 |
+
# the translator pipeline
|
11 |
+
translator = pipeline(
|
12 |
+
"translation",
|
13 |
+
model="kaiku03/open_subtitles-finetuned-opus-mt-en-tl-accelerate"
|
14 |
+
)
|
15 |
+
|
16 |
+
|
17 |
+
# function for the gradio app
|
18 |
+
def fn_translator(prompt):
|
19 |
+
return translator(prompt)[0]['translation_text']
|
20 |
+
|
21 |
+
|
22 |
+
# gradio app
|
23 |
+
# Define example inputs and outputs
|
24 |
+
examples = [
|
25 |
+
"your such an idiot",
|
26 |
+
"lightning fast",
|
27 |
+
"no one likes me",
|
28 |
+
]
|
29 |
+
|
30 |
+
iface = gr.Interface(
|
31 |
+
fn=fn_translator,
|
32 |
+
inputs='text',
|
33 |
+
outputs=gr.Label(label="translation"),
|
34 |
+
examples=[
|
35 |
+
[ex] for ex in examples
|
36 |
+
],
|
37 |
+
title='English to Tagalog translator',
|
38 |
+
description='This demo performs language translation from English to Tagalog.',
|
39 |
+
article='All done by Kaiku',
|
40 |
+
)
|
41 |
+
|
42 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
gradio==3.40
|
3 |
+
torch
|
4 |
+
|
5 |
+
|