import streamlit as st from transformers import pipeline import json # 设置页面配置 st.set_page_config(page_title="中文垃圾信息分类器", page_icon="🚫", layout="wide") # 加载中文垃圾信息分类器 @st.cache_resource def load_classifier(): return pipeline("text-classification", model="app-x/chinese_spam_classifier") classifier = load_classifier() st.title("🚫 中文垃圾信息分类器") st.write("使用 app-x/chinese_spam_classifier 模型进行中文文本的垃圾信息分类。") # 创建两列布局 col1, col2 = st.columns([2, 1]) with col1: # 创建文本输入框 text_input = st.text_area("请输入中文文本:", height=200) if st.button("分类", key="classify_button"): if text_input: with st.spinner("正在分析..."): # 进行分类 result = classifier(text_input)[0] label = "垃圾信息" if result["label"] == "LABEL_1" else "正常信息" confidence = result["score"] # 创建JSON格式的结果 json_result = { "input_text": text_input, "classification": label, "confidence": confidence, "raw_output": result } # 显示结果 st.subheader("分类结果:") if label == "垃圾信息": st.error(f"⚠️ {label}") else: st.success(f"✅ {label}") st.write(f"置信度: {confidence:.2f}") st.progress(confidence) # 显示JSON格式的结果 st.subheader("JSON 格式的详细结果:") st.json(json_result) else: st.warning("请输入文本后再进行分类。") with col2: st.subheader("使用说明") st.write(""" 1. 在左侧文本框中输入您想要分类的中文文本。 2. 点击"分类"按钮。 3. 系统将分析文本并显示结果。 4. 结果包括分类(垃圾信息或正常信息)、置信度和JSON格式的详细输出。 """) st.subheader("关于模型") st.write(""" 本分类器使用了 app-x/chinese_spam_classifier 模型, 该模型基于大规模中文数据集训练,能够有效识别各种类型的垃圾信息。 """) st.subheader("免责声明") st.info(""" 此分类器仅作为辅助工具,不应完全依赖其结果。 请始终保持警惕,谨慎处理可疑信息。 """) # 添加页脚 st.markdown("---") st.markdown("由 Streamlit 和 Hugging Face 提供支持 | 作者:[app-x]")