Spaces:
Sleeping
Sleeping
[email protected]
commited on
Commit
·
9a4d4bb
1
Parent(s):
2d32991
Add simple translation app with Gradio
Browse files- app.py +22 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Pipeline dịch EN -> VI
|
| 5 |
+
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-vi")
|
| 6 |
+
|
| 7 |
+
def translate(text):
|
| 8 |
+
if not text.strip():
|
| 9 |
+
return "Vui lòng nhập câu tiếng Anh."
|
| 10 |
+
result = translator(text, max_length=400)
|
| 11 |
+
return result[0]["translation_text"]
|
| 12 |
+
|
| 13 |
+
demo = gr.Interface(
|
| 14 |
+
fn=translate,
|
| 15 |
+
inputs=gr.Textbox(lines=3, label="Nhập câu TIẾNG ANH"),
|
| 16 |
+
outputs=gr.Textbox(lines=3, label="Kết quả TIẾNG VIỆT"),
|
| 17 |
+
title="M33 - Demo dịch EN → VI trên Hugging Face Spaces",
|
| 18 |
+
description="Ứng dụng web AI đơn giản dùng Gradio + Transformers.",
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
if __name__ == "__main__":
|
| 22 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
transformers
|
| 3 |
+
torch
|