JenniferHJF commited on
Commit
cfd7476
·
verified ·
1 Parent(s): 329843e

Update app.py

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