Update app.py
Browse files
app.py
CHANGED
@@ -74,7 +74,11 @@ st.markdown("## Input or Upload Text for Classification")
|
|
74 |
col1, col2 = st.columns([2, 1])
|
75 |
|
76 |
with col1:
|
77 |
-
user_input = st.text_area(
|
|
|
|
|
|
|
|
|
78 |
if st.button("Analyze Text"):
|
79 |
with st.spinner("Processing..."):
|
80 |
try:
|
@@ -135,18 +139,25 @@ if st.session_state.history:
|
|
135 |
)
|
136 |
st.plotly_chart(radar_fig)
|
137 |
|
138 |
-
#
|
139 |
-
st.markdown("### Top
|
140 |
categories = df['label'].unique()
|
141 |
for cat in categories:
|
142 |
-
cat_df = df[df['label'] == cat].sort_values(by='score', ascending=False)
|
143 |
st.markdown(f"**{cat}**")
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
with st.expander("Show more"):
|
149 |
-
for
|
150 |
-
st.markdown(f"- `{
|
151 |
else:
|
152 |
st.info("No data available. Please analyze some text first.")
|
|
|
74 |
col1, col2 = st.columns([2, 1])
|
75 |
|
76 |
with col1:
|
77 |
+
user_input = st.text_area(
|
78 |
+
"Enter sentence with emojis:",
|
79 |
+
value="春竹你🐎是不是💩了,窩🌿泥🐎SB",
|
80 |
+
height=150
|
81 |
+
)
|
82 |
if st.button("Analyze Text"):
|
83 |
with st.spinner("Processing..."):
|
84 |
try:
|
|
|
139 |
)
|
140 |
st.plotly_chart(radar_fig)
|
141 |
|
142 |
+
# Analyze words related to each offensive category
|
143 |
+
st.markdown("### Top Offensive Terms by Category")
|
144 |
categories = df['label'].unique()
|
145 |
for cat in categories:
|
|
|
146 |
st.markdown(f"**{cat}**")
|
147 |
+
# collect max score per word in texts of this category
|
148 |
+
word_scores = {}
|
149 |
+
for _, row in df[df['label'] == cat].iterrows():
|
150 |
+
words = row['text'].split()
|
151 |
+
for w in words:
|
152 |
+
word_scores[w] = max(word_scores.get(w, 0), row['score'])
|
153 |
+
sorted_words = sorted(word_scores.items(), key=lambda x: x[1], reverse=True)
|
154 |
+
# display top 5 by default
|
155 |
+
for w, s in sorted_words[:5]:
|
156 |
+
st.markdown(f"- `{w}` ({s:.2%})")
|
157 |
+
# show more if exists
|
158 |
+
if len(sorted_words) > 5:
|
159 |
with st.expander("Show more"):
|
160 |
+
for w, s in sorted_words[5:]:
|
161 |
+
st.markdown(f"- `{w}` ({s:.2%})")
|
162 |
else:
|
163 |
st.info("No data available. Please analyze some text first.")
|