Spaces:
Sleeping
Sleeping
xxxxxx
commited on
Commit
·
2cdac3e
1
Parent(s):
229dc8e
update
Browse files- app.py +24 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# 加载中文垃圾邮件分类器
|
5 |
+
classifier = pipeline("text-classification", model="app-x/chinese_spam_classifier")
|
6 |
+
|
7 |
+
def classify_text(text):
|
8 |
+
result = classifier(text)[0]
|
9 |
+
label = "垃圾邮件" if result["label"] == "LABEL_1" else "正常邮件"
|
10 |
+
confidence = result["score"]
|
11 |
+
return f"{label} (置信度: {confidence:.2f})"
|
12 |
+
|
13 |
+
# 创建 Gradio 界面
|
14 |
+
iface = gr.Interface(
|
15 |
+
fn=classify_text,
|
16 |
+
inputs=gr.Textbox(lines=5, placeholder="请输入中文文本..."),
|
17 |
+
outputs="text",
|
18 |
+
title="中文垃圾邮件分类器",
|
19 |
+
description="使用 app-x/chinese_spam_classifier 模型进行中文文本的垃圾邮件分类。"
|
20 |
+
)
|
21 |
+
|
22 |
+
# 启动应用
|
23 |
+
iface.launch()
|
24 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
transformers
|
3 |
+
torch
|
4 |
+
|