Spaces:
Sleeping
Sleeping
eliezerjasper
commited on
Commit
•
9d9a4c2
1
Parent(s):
bb0bb16
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr # UI library
|
2 |
+
from transformers import pipeline # Transformers pipeline
|
3 |
+
|
4 |
+
model_checkpoint_en2fil = "SalamaThanks/SalamaThanksTransformer_en2fil_v3"
|
5 |
+
model_checkpoint_fil2en = "SalamaThanks/SalamaThanksTransformer_fil2en_v3"
|
6 |
+
|
7 |
+
translator_en2fil = pipeline("translation", model = model_checkpoint_en2fil)
|
8 |
+
translator_fil2en = pipeline("translation", model = model_checkpoint_fil2en)
|
9 |
+
|
10 |
+
def transformer_en2fil(from_text):
|
11 |
+
results = translator_en2fil(from_text)
|
12 |
+
return results[0]['translation_text']
|
13 |
+
|
14 |
+
def transformer_fil2en(from_text):
|
15 |
+
results = translator_fil2en(from_text)
|
16 |
+
return results[0]['translation_text']
|
17 |
+
|
18 |
+
def check_lang(lang, from_text):
|
19 |
+
if lang == "English-to-Filipino":
|
20 |
+
return transformer_en2fil(from_text)
|
21 |
+
elif lang == "Filipino-to-English":
|
22 |
+
return transformer_fil2en(from_text)
|
23 |
+
|
24 |
+
interface = gr.Interface(
|
25 |
+
fn=check_lang,
|
26 |
+
inputs=[
|
27 |
+
gr.inputs.Radio(["English-to-Filipino", "Filipino-to-English"]),
|
28 |
+
gr.inputs.Textbox(lines=4, placeholder='Input Text to Translate:')],
|
29 |
+
outputs='text'
|
30 |
+
)
|
31 |
+
|
32 |
+
interface.launch(debug=True)
|