G35 / app.py
JenniferHJF's picture
Update app.py
cfd7476 verified
raw
history blame
1.35 kB
import streamlit as st
from agent import classify_emoji_text
# ✅ 页面配置
st.set_page_config(page_title="Emoji Offensive Text Detector", page_icon="🚨", layout="wide")
# ✅ 页面标题
st.title("🧠 Emoji-based Offensive Language Classifier")
st.markdown("""
This application translates emojis in a sentence and classifies whether the final sentence is offensive or not using two AI models.
- The **first model** translates emoji or symbolic phrases into standard Chinese text.
- The **second model** performs offensive language detection.
""")
# ✅ 输入区域
default_text = "你是🐷"
text = st.text_area("✍️ Input your sentence here:", value=default_text, height=150)
# ✅ 触发按钮
if st.button("🚦 Analyze"):
with st.spinner("🔍 Processing..."):
try:
translated, label, score = classify_emoji_text(text)
# 输出结果显示(修复多行字符串语法)
st.markdown("### 🔄 Translated sentence:")
st.code(translated, language="text")
st.markdown(f"### 🎯 Prediction: `{label}`")
st.markdown(f"### 📊 Confidence Score: `{score:.2%}`")
except Exception as e:
st.error(f"❌ An error occurred during processing:\n\n{e}")
else:
st.info("👈 Please input text and click the button to classify.")