File size: 711 Bytes
9a4d4bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import gradio as gr
from transformers import pipeline

# Pipeline dịch EN -> VI
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-vi")

def translate(text):
    if not text.strip():
        return "Vui lòng nhập câu tiếng Anh."
    result = translator(text, max_length=400)
    return result[0]["translation_text"]

demo = gr.Interface(
    fn=translate,
    inputs=gr.Textbox(lines=3, label="Nhập câu TIẾNG ANH"),
    outputs=gr.Textbox(lines=3, label="Kết quả TIẾNG VIỆT"),
    title="M33 - Demo dịch EN → VI trên Hugging Face Spaces",
    description="Ứng dụng web AI đơn giản dùng Gradio + Transformers.",
)

if __name__ == "__main__":
    demo.launch()