Spaces:
Running
Running
kovacsvi
commited on
Commit
·
4ce3fc4
1
Parent(s):
77eca8d
relative frequency in percentages
Browse files
app.py
CHANGED
@@ -176,14 +176,25 @@ def plot_emotion_barplot(heatmap_data):
|
|
176 |
most_probable_emotions = heatmap_data.idxmax(axis=0)
|
177 |
emotion_counts = most_probable_emotions.value_counts()
|
178 |
all_emotions = heatmap_data.index
|
179 |
-
|
|
|
|
|
|
|
|
|
180 |
palette = [emotion_colors[emotion] for emotion in emotion_frequencies.index]
|
|
|
181 |
fig, ax = plt.subplots(figsize=(8, 6))
|
182 |
-
sns.barplot(x=emotion_frequencies.values, y=emotion_frequencies.index, palette=palette, ax=ax)
|
|
|
|
|
|
|
|
|
|
|
183 |
ax.set_title("Relative Frequencies of Predicted Emotions")
|
184 |
-
ax.set_xlabel("
|
185 |
ax.set_ylabel("Emotions")
|
186 |
plt.tight_layout()
|
|
|
187 |
return fig
|
188 |
|
189 |
def predict_wrapper(text, language):
|
|
|
176 |
most_probable_emotions = heatmap_data.idxmax(axis=0)
|
177 |
emotion_counts = most_probable_emotions.value_counts()
|
178 |
all_emotions = heatmap_data.index
|
179 |
+
|
180 |
+
# Convert to percentage, round to integer
|
181 |
+
emotion_frequencies = (emotion_counts.reindex(all_emotions, fill_value=0) / emotion_counts.sum() * 100).round(0)
|
182 |
+
emotion_frequencies = emotion_frequencies.sort_values(ascending=False)
|
183 |
+
|
184 |
palette = [emotion_colors[emotion] for emotion in emotion_frequencies.index]
|
185 |
+
|
186 |
fig, ax = plt.subplots(figsize=(8, 6))
|
187 |
+
bars = sns.barplot(x=emotion_frequencies.values, y=emotion_frequencies.index, palette=palette, ax=ax)
|
188 |
+
|
189 |
+
# Add % labels on the bars
|
190 |
+
for i, (value, label) in enumerate(zip(emotion_frequencies.values, emotion_frequencies.index)):
|
191 |
+
ax.text(value + 1, i, f"{int(value)}%", va='center')
|
192 |
+
|
193 |
ax.set_title("Relative Frequencies of Predicted Emotions")
|
194 |
+
ax.set_xlabel("Percentage")
|
195 |
ax.set_ylabel("Emotions")
|
196 |
plt.tight_layout()
|
197 |
+
|
198 |
return fig
|
199 |
|
200 |
def predict_wrapper(text, language):
|