aeresd commited on
Commit
d6593c8
·
verified ·
1 Parent(s): 5981972

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -10
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("Enter sentence with emojis:", value="you are 🐷", height=150)
 
 
 
 
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
- # Top inputs per category
139
- st.markdown("### Top Inputs by Offensive Category")
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
- top_n = cat_df.head(5)
145
- for idx, row in top_n.iterrows():
146
- st.markdown(f"- `{row['text']}` ({row['score']:.2%})")
147
- if len(cat_df) > 5:
 
 
 
 
 
 
 
 
148
  with st.expander("Show more"):
149
- for idx, row in cat_df.iloc[5:].iterrows():
150
- st.markdown(f"- `{row['text']}` ({row['score']:.2%})")
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.")