vickeee465 commited on
Commit
acd22e7
·
1 Parent(s): 6947b3f

barplot instead?

Browse files
Files changed (1) hide show
  1. app.py +22 -1
app.py CHANGED
@@ -97,6 +97,27 @@ def plot_emotion_heatmap(heatmap_data):
97
  plt.tight_layout()
98
  return fig
99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  def predict_wrapper(text, language):
101
  model_id = build_huggingface_path(language)
102
  tokenizer_id = "xlm-roberta-large"
@@ -116,7 +137,7 @@ def predict_wrapper(text, language):
116
  print(results)
117
  print(results_heatmap)
118
 
119
- figure = plot_emotion_heatmap(prepare_heatmap_data(results_heatmap))
120
  output_info = f'Prediction was made using the <a href="https://huggingface.co/{model_id}">{model_id}</a> model.'
121
  return results, figure, output_info
122
 
 
97
  plt.tight_layout()
98
  return fig
99
 
100
+
101
+ def plot_emotion_barplot(heatmap_data):
102
+ most_probable_emotions = heatmap_data.idxmax(axis=1)
103
+ emotion_counts = most_probable_emotions.value_counts()
104
+
105
+ # Normalize to get relative frequencies
106
+ emotion_frequencies = (emotion_counts / emotion_counts.sum()).sort_values(ascending=False)
107
+
108
+ fig, ax = plt.subplots(figsize=(8, 6))
109
+ sns.barplot(x=emotion_frequencies.values, y=emotion_frequencies.index, palette="coolwarm", ax=ax)
110
+
111
+ ax.set_title("Relative Frequencies of Most Probable Emotions")
112
+ ax.set_xlabel("Relative Frequency")
113
+ ax.set_ylabel("Emotions")
114
+
115
+ for i, value in enumerate(emotion_frequencies.values):
116
+ ax.text(value + 0.01, i, f"{value:.2f}", va='center')
117
+
118
+ plt.tight_layout()
119
+ return fig
120
+
121
  def predict_wrapper(text, language):
122
  model_id = build_huggingface_path(language)
123
  tokenizer_id = "xlm-roberta-large"
 
137
  print(results)
138
  print(results_heatmap)
139
 
140
+ figure = plot_emotion_barplot(prepare_heatmap_data(results_heatmap))
141
  output_info = f'Prediction was made using the <a href="https://huggingface.co/{model_id}">{model_id}</a> model.'
142
  return results, figure, output_info
143