Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,51 @@
|
|
1 |
import streamlit as st
|
2 |
from agent import classify_emoji_text
|
3 |
|
4 |
-
|
5 |
-
st.
|
|
|
6 |
|
7 |
-
st.markdown("
|
8 |
|
9 |
-
|
10 |
-
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from agent import classify_emoji_text
|
3 |
|
4 |
+
# 页面配置
|
5 |
+
st.set_page_config(page_title="Emoji Offensive Classifier", page_icon="🧠", layout="wide")
|
6 |
+
st.title("🔥 Emoji-Based Offensive Text Classifier")
|
7 |
|
8 |
+
st.markdown("Detect potentially offensive Chinese sentences enhanced with emojis, slang, or homophones.")
|
9 |
|
10 |
+
# 分两栏布局
|
11 |
+
left_col, right_col = st.columns([2, 1])
|
12 |
|
13 |
+
# 左侧输入
|
14 |
+
with left_col:
|
15 |
+
st.subheader("📥 Input Text")
|
16 |
+
example = "你是🐷"
|
17 |
+
user_input = st.text_area("Paste your message here:", value=example, height=200)
|
18 |
+
model_choice = st.selectbox(
|
19 |
+
"Choose offensive classifier model:",
|
20 |
+
options=[
|
21 |
+
"cardiffnlp/twitter-roberta-base-offensive",
|
22 |
+
"facebook/roberta-hate-speech-dynabench",
|
23 |
+
"microsoft/deberta-v3-base"
|
24 |
+
],
|
25 |
+
index=0,
|
26 |
+
help="Select a backend classifier. LLM used for emoji translation is fixed (Qwen1.5-emoji)."
|
27 |
+
)
|
28 |
+
|
29 |
+
if st.button("🚦 Run Detection"):
|
30 |
+
with st.spinner("Running model inference..."):
|
31 |
+
translated, label, score = classify_emoji_text(user_input, model_id=model_choice)
|
32 |
+
st.session_state.result = {
|
33 |
+
"text": translated,
|
34 |
+
"label": label,
|
35 |
+
"score": score
|
36 |
+
}
|
37 |
+
else:
|
38 |
+
st.info("Click the button to start analysis.")
|
39 |
+
|
40 |
+
# 右侧输出
|
41 |
+
with right_col:
|
42 |
+
st.subheader("📊 Analysis Results")
|
43 |
+
|
44 |
+
if "result" in st.session_state:
|
45 |
+
result = st.session_state.result
|
46 |
+
st.success("✅ Classification Complete")
|
47 |
+
st.markdown(f"**Translated Text:** `{result['text']}`")
|
48 |
+
st.markdown(f"**Prediction:** `{result['label']}`")
|
49 |
+
st.markdown(f"**Confidence Score:** `{result['score']:.2%}`")
|
50 |
+
else:
|
51 |
+
st.markdown("⚠️ No output yet. Run detection to see results.")
|