Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,51 +1,33 @@
|
|
1 |
import streamlit as st
|
2 |
-
from agent import classify_emoji_text
|
3 |
|
4 |
-
|
5 |
-
st.
|
6 |
-
st.title("🔥 Emoji-Based Offensive Text Classifier")
|
7 |
|
8 |
-
st.markdown("
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
#
|
11 |
-
|
|
|
|
|
12 |
|
13 |
-
#
|
14 |
-
|
15 |
-
|
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 |
-
|
30 |
-
|
31 |
-
|
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 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
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.")
|
|
|
1 |
import streamlit as st
|
2 |
+
from agent import classify_emoji_text, available_models
|
3 |
|
4 |
+
st.set_page_config(page_title="Emoji Offensive Classifier", page_icon="🚨", layout="wide")
|
5 |
+
st.title("🚨 Offensive Text Detection Agent (with Emoji Translation)")
|
|
|
6 |
|
7 |
+
st.markdown("""
|
8 |
+
This demo uses a two-step AI agent:
|
9 |
+
1. Translates emojis & phonetic expressions into clear Chinese using a fine-tuned Qwen model.
|
10 |
+
2. Classifies the translated sentence for offensiveness using a selectable large language model.
|
11 |
+
""")
|
12 |
|
13 |
+
# 左侧:输入区
|
14 |
+
st.subheader("① Enter a sentence with emoji or homophones:")
|
15 |
+
example = "你是🐷,好像🤡"
|
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("Running multi-stage agent pipeline..."):
|
24 |
+
translated, label, score = classify_emoji_text(text, model_choice)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
+
st.success("✅ Completed!")
|
27 |
+
st.markdown(f"### 🔄 Translated sentence:\n```
|
28 |
+
{translated}
|
29 |
+
```")
|
30 |
+
st.markdown(f"### 🎯 Prediction: `{label}`")
|
31 |
+
st.markdown(f"### 📊 Confidence: `{score:.2%}`")
|
32 |
+
else:
|
33 |
+
st.info("Click 'Analyze' to start inference.")
|
|
|
|
|
|
|
|