Smail/test/plugins/spam_block/backend_test.py
smail f60d3b0880
Some checks are pending
Security Checks / security (push) Waiting to run
整理前后端与测试构建目录并完善配置和安全引导
统一 frontend、backend、test、test-log 和 out 目录,更新构建、部署及测试入口;纳入配置管理兼容与首次安全引导修复;排除本机配置、密钥和测试产物。
2026-09-05 19:19:52 +08:00

36 lines
964 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
from pathlib import Path
import numpy as np
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '1' # silence TF INFO messages
import tensorflow as tf
save_path = str(Path(__file__).resolve().parents[3] / 'backend/hooks/spam_block/emotion_model/1')
model = tf.keras.models.load_model(save_path, compile=False)
model.summary()
CLASSES = {
0:'普通邮件',
1:'广告邮件',
2:'诈骗邮件'
}
def predict_emotions(txt):
# recall it is multi-class so we need to get all prediction above a threshold (0.5)
input = tf.constant( np.array([txt]) , dtype=tf.string )
preds = model(input)[0]
maxClass = -1
maxScore = 0
for idx in range(3):
if preds[idx] > maxScore:
maxScore = preds[idx]
maxClass = idx
return maxClass
maxClass = predict_emotions("各位同事请注意 这里是110,请大家立刻把银行卡账号密码回复发给我!")
print("这个邮件属于:",CLASSES[maxClass])