JenniferHJF commited on
Commit
39efac9
·
verified ·
1 Parent(s): 280fee3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -13
app.py CHANGED
@@ -1,19 +1,51 @@
1
  import streamlit as st
2
  from agent import classify_emoji_text
3
 
4
- st.set_page_config(page_title="Emoji Offensive Classifier", page_icon="🤖")
5
- st.title("🧠 Emoji Offensive Text Detector")
 
6
 
7
- st.markdown("Enter a sentence containing emoji and check if it’s offensive.")
8
 
9
- example = "你是🐷"
10
- text = st.text_area("Enter text:", value=example, height=100)
11
 
12
- if st.button("Analyze"):
13
- with st.spinner("Processing..."):
14
- translated, label, score = classify_emoji_text(text)
15
- st.markdown(f"**Translated Text:** `{translated}`")
16
- st.markdown(f"**Prediction:** `{label}`")
17
- st.markdown(f"**Confidence:** `{score:.2%}`")
18
- else:
19
- st.info("Click the button to start analysis.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.")