Spaces:
Runtime error
Runtime error
hieunguyen1053
commited on
Commit
•
4eaa873
1
Parent(s):
1a6e247
init
Browse files- README.md +3 -2
- app.py +21 -0
- requirements.txt +6 -0
README.md
CHANGED
@@ -1,11 +1,12 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
colorFrom: indigo
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
7 |
sdk_version: 3.1.4
|
8 |
app_file: app.py
|
|
|
9 |
pinned: false
|
10 |
license: apache-2.0
|
11 |
---
|
|
|
1 |
---
|
2 |
+
title: MT En-Vi
|
3 |
+
emoji: 🇻🇳
|
4 |
colorFrom: indigo
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
7 |
sdk_version: 3.1.4
|
8 |
app_file: app.py
|
9 |
+
models: icon-it-tdtu/mt-en-vi-optimum
|
10 |
pinned: false
|
11 |
license: apache-2.0
|
12 |
---
|
app.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
from optimum.onnxruntime import ORTModelForSeq2SeqLM
|
4 |
+
from transformers import AutoTokenizer
|
5 |
+
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained("icon-it-tdtu/mt-en-vi-optimum")
|
7 |
+
model = ORTModelForSeq2SeqLM.from_pretrained("icon-it-tdtu/mt-en-vi-optimum")
|
8 |
+
|
9 |
+
def translate(text):
|
10 |
+
inputs = tokenizer(text, return_tensors='pt')
|
11 |
+
outputs = model.generate(**inputs)
|
12 |
+
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
13 |
+
return result
|
14 |
+
|
15 |
+
iface = gr.Interface(
|
16 |
+
fn=translate,
|
17 |
+
inputs=gr.inputs.Textbox(lines=2, placeholder="Enter English text to translate..."),
|
18 |
+
outputs="text",
|
19 |
+
theme="huggingface"
|
20 |
+
)
|
21 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
transformers==4.21.1
|
2 |
+
datasets==2.4.0
|
3 |
+
optimum==1.3.0
|
4 |
+
sacremoses==0.0.53
|
5 |
+
onnxruntime==1.12.1
|
6 |
+
onnx==1.12.0
|