JenniferHJF commited on
Commit
7c8ae88
·
verified ·
1 Parent(s): 39efac9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -44
app.py CHANGED
@@ -1,51 +1,33 @@
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.")
 
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.")