Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,33 +1,36 @@
|
|
1 |
import streamlit as st
|
2 |
-
from agent import classify_emoji_text
|
3 |
|
4 |
-
|
5 |
-
st.
|
|
|
|
|
|
|
6 |
|
7 |
st.markdown("""
|
8 |
-
This
|
9 |
-
|
10 |
-
|
11 |
""")
|
12 |
|
13 |
-
#
|
14 |
-
|
15 |
-
|
16 |
-
text = st.text_area("Input text:", value=example, height=120)
|
17 |
-
|
18 |
-
# 右侧:模型选择区
|
19 |
-
st.subheader("② Select classification model:")
|
20 |
-
model_choice = st.selectbox("Choose a classifier", options=list(available_models.keys()))
|
21 |
|
|
|
22 |
if st.button("🚦 Analyze"):
|
23 |
-
with st.spinner("
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
32 |
else:
|
33 |
-
st.info("
|
|
|
1 |
import streamlit as st
|
2 |
+
from agent import classify_emoji_text
|
3 |
|
4 |
+
# ✅ 页面配置
|
5 |
+
st.set_page_config(page_title="Emoji Offensive Text Detector", page_icon="🚨", layout="wide")
|
6 |
+
|
7 |
+
# ✅ 页面标题
|
8 |
+
st.title("🧠 Emoji-based Offensive Language Classifier")
|
9 |
|
10 |
st.markdown("""
|
11 |
+
This application translates emojis in a sentence and classifies whether the final sentence is offensive or not using two AI models.
|
12 |
+
- The **first model** translates emoji or symbolic phrases into standard Chinese text.
|
13 |
+
- The **second model** performs offensive language detection.
|
14 |
""")
|
15 |
|
16 |
+
# ✅ 输入区域
|
17 |
+
default_text = "你是🐷"
|
18 |
+
text = st.text_area("✍️ Input your sentence here:", value=default_text, height=150)
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
+
# ✅ 触发按钮
|
21 |
if st.button("🚦 Analyze"):
|
22 |
+
with st.spinner("🔍 Processing..."):
|
23 |
+
try:
|
24 |
+
translated, label, score = classify_emoji_text(text)
|
25 |
+
|
26 |
+
# 输出结果显示(修复多行字符串语法)
|
27 |
+
st.markdown("### 🔄 Translated sentence:")
|
28 |
+
st.code(translated, language="text")
|
29 |
+
|
30 |
+
st.markdown(f"### 🎯 Prediction: `{label}`")
|
31 |
+
st.markdown(f"### 📊 Confidence Score: `{score:.2%}`")
|
32 |
+
|
33 |
+
except Exception as e:
|
34 |
+
st.error(f"❌ An error occurred during processing:\n\n{e}")
|
35 |
else:
|
36 |
+
st.info("👈 Please input text and click the button to classify.")
|