Spaces:
Sleeping
Sleeping
xxxxxx
commited on
Commit
·
b190df6
1
Parent(s):
2cdac3e
update
Browse files- app.py +21 -17
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -1,24 +1,28 @@
|
|
| 1 |
-
import
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
# 加载中文垃圾邮件分类器
|
| 5 |
-
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
|
| 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 |
-
|
| 14 |
-
|
| 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 |
-
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
# 加载中文垃圾邮件分类器
|
| 5 |
+
@st.cache_resource
|
| 6 |
+
def load_classifier():
|
| 7 |
+
return pipeline("text-classification", model="app-x/chinese_spam_classifier")
|
| 8 |
|
| 9 |
+
classifier = load_classifier()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
st.title("中文垃圾信息分类器")
|
| 12 |
+
st.write("使用 app-x/chinese_spam_classifier 模型进行中文文本的垃圾信息分类。")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
# 创建文本输入框
|
| 15 |
+
text_input = st.text_area("请输入中文文本:", height=150)
|
| 16 |
|
| 17 |
+
if st.button("分类"):
|
| 18 |
+
if text_input:
|
| 19 |
+
# 进行分类
|
| 20 |
+
result = classifier(text_input)[0]
|
| 21 |
+
label = "垃圾信息" if result["label"] == "LABEL_1" else "正常信息"
|
| 22 |
+
confidence = result["score"]
|
| 23 |
+
|
| 24 |
+
# 显示结果
|
| 25 |
+
st.write(f"分类结果: {label}")
|
| 26 |
+
st.write(f"置信度: {confidence:.2f}")
|
| 27 |
+
else:
|
| 28 |
+
st.warning("请输入文本后再进行分类。")
|
requirements.txt
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
-
|
| 2 |
transformers
|
| 3 |
torch
|
| 4 |
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
transformers
|
| 3 |
torch
|
| 4 |
|
| 5 |
+
|