Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -12,16 +12,19 @@ MODEL_PATH = "fallinluv8/nexore-toxic-model"
|
|
| 12 |
|
| 13 |
# Bạn có thể thêm từ vào đây tùy ý
|
| 14 |
HARD_BLACKLIST = [
|
| 15 |
-
"đéo"
|
|
|
|
|
|
|
|
|
|
| 16 |
]
|
| 17 |
|
| 18 |
classifier = None
|
| 19 |
-
startup_error = None
|
| 20 |
|
| 21 |
@app.on_event("startup")
|
| 22 |
def load_model():
|
| 23 |
global classifier, startup_error
|
| 24 |
-
print(f"
|
| 25 |
try:
|
| 26 |
# Load Tokenizer
|
| 27 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
|
|
@@ -89,7 +92,7 @@ async def predict_toxicity(request: ToxicRequest):
|
|
| 89 |
# Chỉ chạy AI nếu blacklist chưa bắt được hoặc để bổ sung thêm từ vi phạm
|
| 90 |
try:
|
| 91 |
results = classifier(request.text)
|
| 92 |
-
print(f"
|
| 93 |
|
| 94 |
for entity in results:
|
| 95 |
score = float(entity['score'])
|
|
@@ -108,11 +111,11 @@ async def predict_toxicity(request: ToxicRequest):
|
|
| 108 |
max_score = score
|
| 109 |
|
| 110 |
# Nếu AI tìm thấy từ có độ tin cậy cao
|
| 111 |
-
if max_score > 0.
|
| 112 |
is_toxic = True
|
| 113 |
|
| 114 |
except Exception as e:
|
| 115 |
-
print(f"
|
| 116 |
# Nếu blacklist đã bắt được thì bỏ qua lỗi AI, trả về kết quả blacklist
|
| 117 |
if not is_toxic:
|
| 118 |
raise HTTPException(status_code=500, detail=f"AI Error: {str(e)}")
|
|
|
|
| 12 |
|
| 13 |
# Bạn có thể thêm từ vào đây tùy ý
|
| 14 |
HARD_BLACKLIST = [
|
| 15 |
+
"đéo", "đ**", "dm", "dcm", "đm", "vcl", "vl",
|
| 16 |
+
"cc", "cmn", "cmm", "lồn", "l**", "đĩ", "đ**",
|
| 17 |
+
"cặc", "c**", "buồi", "bu**", "đụ", "đụ mẹ",
|
| 18 |
+
"đụ bố", "đụ con mẹ mày", "đụ con", "đụ mày"
|
| 19 |
]
|
| 20 |
|
| 21 |
classifier = None
|
| 22 |
+
startup_error = None
|
| 23 |
|
| 24 |
@app.on_event("startup")
|
| 25 |
def load_model():
|
| 26 |
global classifier, startup_error
|
| 27 |
+
print(f" [STARTUP] Đang tải Model từ Hub: {MODEL_PATH}...")
|
| 28 |
try:
|
| 29 |
# Load Tokenizer
|
| 30 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
|
|
|
|
| 92 |
# Chỉ chạy AI nếu blacklist chưa bắt được hoặc để bổ sung thêm từ vi phạm
|
| 93 |
try:
|
| 94 |
results = classifier(request.text)
|
| 95 |
+
print(f" [AI SEE] {results}") # Log để debug
|
| 96 |
|
| 97 |
for entity in results:
|
| 98 |
score = float(entity['score'])
|
|
|
|
| 111 |
max_score = score
|
| 112 |
|
| 113 |
# Nếu AI tìm thấy từ có độ tin cậy cao
|
| 114 |
+
if max_score > 0.9:
|
| 115 |
is_toxic = True
|
| 116 |
|
| 117 |
except Exception as e:
|
| 118 |
+
print(f" [AI ERROR] {e}")
|
| 119 |
# Nếu blacklist đã bắt được thì bỏ qua lỗi AI, trả về kết quả blacklist
|
| 120 |
if not is_toxic:
|
| 121 |
raise HTTPException(status_code=500, detail=f"AI Error: {str(e)}")
|