Spaces:
Build error
Build error
update
Browse files
app.py
CHANGED
|
@@ -1,28 +1,80 @@
|
|
| 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 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
+
import json
|
| 4 |
|
| 5 |
+
# 设置页面配置
|
| 6 |
+
st.set_page_config(page_title="中文垃圾信息分类器", page_icon="🚫", layout="wide")
|
| 7 |
+
|
| 8 |
+
# 加载中文垃圾信息分类器
|
| 9 |
@st.cache_resource
|
| 10 |
def load_classifier():
|
| 11 |
return pipeline("text-classification", model="app-x/chinese_spam_classifier")
|
| 12 |
|
| 13 |
classifier = load_classifier()
|
| 14 |
|
| 15 |
+
st.title("🚫 中文垃圾信息分类器")
|
| 16 |
st.write("使用 app-x/chinese_spam_classifier 模型进行中文文本的垃圾信息分类。")
|
| 17 |
|
| 18 |
+
# 创建两列布局
|
| 19 |
+
col1, col2 = st.columns([2, 1])
|
| 20 |
+
|
| 21 |
+
with col1:
|
| 22 |
+
# 创建文本输入框
|
| 23 |
+
text_input = st.text_area("请输入中文文本:", height=200)
|
| 24 |
+
|
| 25 |
+
if st.button("分类", key="classify_button"):
|
| 26 |
+
if text_input:
|
| 27 |
+
with st.spinner("正在分析..."):
|
| 28 |
+
# 进行分类
|
| 29 |
+
result = classifier(text_input)[0]
|
| 30 |
+
label = "垃圾信息" if result["label"] == "LABEL_1" else "正常信息"
|
| 31 |
+
confidence = result["score"]
|
| 32 |
+
|
| 33 |
+
# 创建JSON格式的结果
|
| 34 |
+
json_result = {
|
| 35 |
+
"input_text": text_input,
|
| 36 |
+
"classification": label,
|
| 37 |
+
"confidence": confidence,
|
| 38 |
+
"raw_output": result
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
# 显示结果
|
| 42 |
+
st.subheader("分类结果:")
|
| 43 |
+
if label == "垃圾信息":
|
| 44 |
+
st.error(f"⚠️ {label}")
|
| 45 |
+
else:
|
| 46 |
+
st.success(f"✅ {label}")
|
| 47 |
+
|
| 48 |
+
st.write(f"置信度: {confidence:.2f}")
|
| 49 |
+
st.progress(confidence)
|
| 50 |
+
|
| 51 |
+
# 显示JSON格式的结果
|
| 52 |
+
st.subheader("JSON 格式的详细结果:")
|
| 53 |
+
st.json(json_result)
|
| 54 |
+
else:
|
| 55 |
+
st.warning("请输入文本后再进行分类。")
|
| 56 |
+
|
| 57 |
+
with col2:
|
| 58 |
+
st.subheader("使用说明")
|
| 59 |
+
st.write("""
|
| 60 |
+
1. 在左侧文本框中输入您想要分类的中文文本。
|
| 61 |
+
2. 点击"分类"按钮。
|
| 62 |
+
3. 系统将分析文本并显示结果。
|
| 63 |
+
4. 结果包括分类(垃圾信息或正常信息)、置信度和JSON格式的详细输出。
|
| 64 |
+
""")
|
| 65 |
+
|
| 66 |
+
st.subheader("关于模型")
|
| 67 |
+
st.write("""
|
| 68 |
+
本分类器使用了 app-x/chinese_spam_classifier 模型,
|
| 69 |
+
该模型基于大规模中文数据集训练,能够有效识别各种类型的垃圾信息。
|
| 70 |
+
""")
|
| 71 |
+
|
| 72 |
+
st.subheader("免责声明")
|
| 73 |
+
st.info("""
|
| 74 |
+
此分类器仅作为辅助工具,不应完全依赖其结果。
|
| 75 |
+
请始终保持警惕,谨慎处理可疑信息。
|
| 76 |
+
""")
|
| 77 |
+
|
| 78 |
+
# 添加页脚
|
| 79 |
+
st.markdown("---")
|
| 80 |
+
st.markdown("由 Streamlit 和 Hugging Face 提供支持 | 作者:[app-x]")
|