Spaces:
Sleeping
Sleeping
code refactoring
Browse files
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
from model import *
|
4 |
+
|
5 |
+
model = build_transformer(2000, 2500, 200, 200)
|
6 |
+
translator = pipeline('translation_en_to_fr')
|
7 |
+
|
8 |
+
def translate(text):
|
9 |
+
result = translator(text)[0]['translation_text']
|
10 |
+
return result
|
11 |
+
|
12 |
+
examples = [
|
13 |
+
"Hi, How are you?",
|
14 |
+
"I don't understand.",
|
15 |
+
"I am sorry."
|
16 |
+
]
|
17 |
+
|
18 |
+
demo = gr.Interface(
|
19 |
+
fn = translate,
|
20 |
+
inputs = [
|
21 |
+
gr.Textbox(label = "Enter Sentence")
|
22 |
+
],
|
23 |
+
outputs = [
|
24 |
+
gr.Textbox(label="Translated Text")
|
25 |
+
],
|
26 |
+
examples = examples,
|
27 |
+
cache_examples = True
|
28 |
+
)
|
29 |
+
|
30 |
+
demo.launch()
|