Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,26 +1,29 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
#
|
| 4 |
-
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
-
comments = [
|
| 15 |
-
"Bạn thật sự ngu ngốc và kém cỏi.",
|
| 16 |
-
"Hôm nay là một ngày đẹp trời.",
|
| 17 |
-
"Cái này tệ kinh khủng, không ai muốn dùng đâu!"
|
| 18 |
-
]
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, T5ForConditionalGeneration
|
| 3 |
+
import torch
|
| 4 |
|
| 5 |
+
# Dùng đúng tokenizer gốc: t5-small
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained("t5-small")
|
| 7 |
+
model = T5ForConditionalGeneration.from_pretrained("naot97/vietnamese-toxicity-detection_3")
|
| 8 |
|
| 9 |
+
def detect_toxic(text):
|
| 10 |
+
prompt = f"toxic classification: {text}"
|
| 11 |
+
inputs = tokenizer(prompt, return_tensors="pt", truncation=True)
|
| 12 |
|
| 13 |
+
with torch.no_grad():
|
| 14 |
+
outputs = model.generate(
|
| 15 |
+
input_ids=inputs["input_ids"],
|
| 16 |
+
attention_mask=inputs["attention_mask"],
|
| 17 |
+
max_length=10
|
| 18 |
+
)
|
| 19 |
+
decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 20 |
|
| 21 |
+
return f"Toxicity: {decoded}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
gr.Interface(
|
| 24 |
+
fn=detect_toxic,
|
| 25 |
+
inputs="text",
|
| 26 |
+
outputs="text",
|
| 27 |
+
title="Vietnamese Toxicity Detector",
|
| 28 |
+
description="Dựa trên mô hình T5 phát hiện độc hại tiếng Việt"
|
| 29 |
+
).launch()
|