Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
| 3 |
+
|
| 4 |
+
print("Đang tải model...")
|
| 5 |
+
model_name = "tarudesu/ViHateT5-base-HSD"
|
| 6 |
+
try:
|
| 7 |
+
tokenizer = T5Tokenizer.from_pretrained(model_name)
|
| 8 |
+
model = T5ForConditionalGeneration.from_pretrained(model_name)
|
| 9 |
+
print("Tải model thành công!")
|
| 10 |
+
except Exception as e:
|
| 11 |
+
print(f"Lỗi khi tải model: {e}")
|
| 12 |
+
model = None
|
| 13 |
+
|
| 14 |
+
def classify_vietnamese_text(text_to_check):
|
| 15 |
+
if model is None or tokenizer is None:
|
| 16 |
+
return "Lỗi: Model chưa được khởi tạo."
|
| 17 |
+
|
| 18 |
+
input_text = f"hate-speech-detection: {text_to_check}"
|
| 19 |
+
|
| 20 |
+
input_ids = tokenizer(input_text, return_tensors="pt").input_ids
|
| 21 |
+
outputs = model.generate(input_ids, max_length=10)
|
| 22 |
+
|
| 23 |
+
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 24 |
+
return result
|
| 25 |
+
|
| 26 |
+
demo = gr.Interface(
|
| 27 |
+
fn=classify_vietnamese_text,
|
| 28 |
+
inputs=gr.Textbox(lines=2, placeholder="Nhập câu Tiếng Việt cần kiểm tra ở đây..."),
|
| 29 |
+
outputs="text",
|
| 30 |
+
title="Vietnamese Hate Speech Detection",
|
| 31 |
+
description="Một API demo cho model tarudesu/ViHateT5-base-HSD."
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
demo.launch()
|