Update app.py
Browse files
app.py
CHANGED
@@ -119,5 +119,37 @@ if st.session_state.history:
|
|
119 |
radar_fig = px.line_polar(radar_df, r='Score', theta='Category', line_close=True, title="⚠️ Risk Radar by Category")
|
120 |
radar_fig.update_traces(line_color='black')
|
121 |
st.plotly_chart(radar_fig)
|
122 |
-
|
123 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
radar_fig = px.line_polar(radar_df, r='Score', theta='Category', line_close=True, title="⚠️ Risk Radar by Category")
|
120 |
radar_fig.update_traces(line_color='black')
|
121 |
st.plotly_chart(radar_fig)
|
122 |
+
|
123 |
+
# 單詞冒犯性分析模塊
|
124 |
+
st.markdown("### 🧬 Word-level Offensive Correlation")
|
125 |
+
|
126 |
+
last_translated_text = st.session_state.history[-1]["translated"]
|
127 |
+
words = last_translated_text.split()
|
128 |
+
|
129 |
+
word_scores = []
|
130 |
+
for word in words:
|
131 |
+
try:
|
132 |
+
result = classifier(word)[0]
|
133 |
+
word_scores.append({
|
134 |
+
"Word": word,
|
135 |
+
"Label": result["label"],
|
136 |
+
"Score": result["score"]
|
137 |
+
})
|
138 |
+
except:
|
139 |
+
continue
|
140 |
+
|
141 |
+
if word_scores:
|
142 |
+
word_df = pd.DataFrame(word_scores)
|
143 |
+
word_df = word_df.sort_values(by="Score", ascending=False).reset_index(drop=True)
|
144 |
+
|
145 |
+
# 顯示前5個,隱藏表格邊框
|
146 |
+
max_display = 5
|
147 |
+
show_more = st.toggle("Show more words")
|
148 |
+
|
149 |
+
display_df = word_df if show_more else word_df.head(max_display)
|
150 |
+
st.markdown(
|
151 |
+
display_df.to_html(index=False, border=0),
|
152 |
+
unsafe_allow_html=True
|
153 |
+
)
|
154 |
+
else:
|
155 |
+
st.info("❕ No word-level analysis available.")
|