Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,6 +17,12 @@ model = AutoModelForSequenceClassification.from_pretrained(MODEL_DIR)
|
|
| 17 |
model.eval()
|
| 18 |
|
| 19 |
def predict(text):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
inputs = tokenizer(
|
| 21 |
text,
|
| 22 |
return_tensors="pt",
|
|
@@ -30,18 +36,7 @@ def predict(text):
|
|
| 30 |
probs = torch.softmax(outputs.logits, dim=1)[0]
|
| 31 |
|
| 32 |
pred_id = torch.argmax(probs).item()
|
| 33 |
-
|
| 34 |
-
# 直接讀模型 config 裡面的正確標籤
|
| 35 |
pred_label = model.config.id2label[pred_id]
|
| 36 |
confidence = probs[pred_id].item() * 100
|
| 37 |
|
| 38 |
-
return f"{pred_label}(信心度:{confidence:.2f}%)"
|
| 39 |
-
|
| 40 |
-
demo = gr.Interface(
|
| 41 |
-
fn=predict,
|
| 42 |
-
inputs=gr.Textbox(lines=5, placeholder="請輸入可疑文字..."),
|
| 43 |
-
outputs="text",
|
| 44 |
-
title="LINE Bot BERT 詐騙分類 API"
|
| 45 |
-
)
|
| 46 |
-
|
| 47 |
-
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 17 |
model.eval()
|
| 18 |
|
| 19 |
def predict(text):
|
| 20 |
+
romance_words = ["網戀", "交友", "寶貝", "老公", "老婆", "男友", "女友", "愛我", "喜歡我", "感情"]
|
| 21 |
+
money_words = ["匯款", "轉帳", "借錢", "還我", "投資", "入金", "儲值"]
|
| 22 |
+
|
| 23 |
+
if any(w in text for w in romance_words) and any(w in text for w in money_words):
|
| 24 |
+
return "愛情(規則判斷:感情關係 + 金錢要求)"
|
| 25 |
+
|
| 26 |
inputs = tokenizer(
|
| 27 |
text,
|
| 28 |
return_tensors="pt",
|
|
|
|
| 36 |
probs = torch.softmax(outputs.logits, dim=1)[0]
|
| 37 |
|
| 38 |
pred_id = torch.argmax(probs).item()
|
|
|
|
|
|
|
| 39 |
pred_label = model.config.id2label[pred_id]
|
| 40 |
confidence = probs[pred_id].item() * 100
|
| 41 |
|
| 42 |
+
return f"{pred_label}(信心度:{confidence:.2f}%)"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|