Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,22 @@
|
|
| 1 |
-
from transformers import
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
)
|
| 8 |
|
| 9 |
def translate(text):
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
iface = gr.Interface(
|
| 14 |
fn=translate,
|
|
@@ -16,9 +24,8 @@ iface = gr.Interface(
|
|
| 16 |
lines=2,
|
| 17 |
placeholder="Nhập tiếng Nga..."
|
| 18 |
),
|
| 19 |
-
outputs=
|
| 20 |
-
title="🇷🇺 Nga → Việt"
|
| 21 |
-
description="Mini translator for Notion"
|
| 22 |
)
|
| 23 |
|
| 24 |
iface.launch(server_name="0.0.0.0")
|
|
|
|
| 1 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
model_name = "Helsinki-NLP/opus-mt-ru-vi"
|
| 5 |
+
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
| 8 |
|
| 9 |
def translate(text):
|
| 10 |
+
inputs = tokenizer(text, return_tensors="pt")
|
| 11 |
+
|
| 12 |
+
outputs = model.generate(**inputs)
|
| 13 |
+
|
| 14 |
+
translated = tokenizer.decode(
|
| 15 |
+
outputs[0],
|
| 16 |
+
skip_special_tokens=True
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
return translated
|
| 20 |
|
| 21 |
iface = gr.Interface(
|
| 22 |
fn=translate,
|
|
|
|
| 24 |
lines=2,
|
| 25 |
placeholder="Nhập tiếng Nga..."
|
| 26 |
),
|
| 27 |
+
outputs="text",
|
| 28 |
+
title="🇷🇺 Nga → Việt"
|
|
|
|
| 29 |
)
|
| 30 |
|
| 31 |
iface.launch(server_name="0.0.0.0")
|