vickeee465 commited on
Commit
7e66e8d
·
1 Parent(s): 2c43ece

global emotion color coding

Browse files
Files changed (1) hide show
  1. app.py +13 -36
app.py CHANGED
@@ -31,6 +31,15 @@ id2label = {
31
  4: "Joy",
32
  5: "None of Them"
33
  }
 
 
 
 
 
 
 
 
 
34
  def load_spacy_model(model_name="xx_sent_ud_sm"):
35
  try:
36
  model = spacy.load(model_name)
@@ -117,40 +126,6 @@ def plot_emotion_heatmap(heatmap_data):
117
 
118
  return fig
119
 
120
- def plot_sunburst_chart(heatmap_data):
121
- data = []
122
- for item in heatmap_data:
123
- sentence = item['sentence']
124
- emotions = item['emotions']
125
-
126
- sentence_wrapped = "\n".join([sentence[i:i + 50] for i in range(0, len(sentence), 50)])
127
-
128
- for i, score in enumerate(emotions):
129
- data.append({
130
- 'sentence': sentence_wrapped,
131
- 'emotion': id2label[i],
132
- 'score': float(score)
133
- })
134
-
135
- df = pd.DataFrame(data)
136
-
137
- fig = px.sunburst(
138
- df,
139
- path=['sentence', 'emotion'],
140
- values='score',
141
- color='emotion',
142
- hover_data={'score': ':.3f'},
143
- title='Sentence-Level Emotion Confidence'
144
- )
145
-
146
- fig.update_layout(
147
- width=800,
148
- height=800,
149
- margin=dict(t=50, l=0, r=0, b=0)
150
- )
151
-
152
- return fig
153
-
154
 
155
  def plot_average_emotion_pie(heatmap_data):
156
  all_emotion_scores = np.array([item['emotions'] for item in heatmap_data])
@@ -173,7 +148,8 @@ def plot_average_emotion_pie(heatmap_data):
173
  labels=labels_filtered,
174
  autopct='%1.1f%%',
175
  startangle=140,
176
- textprops={'fontsize': 12}
 
177
  )
178
 
179
  ax.axis('equal') # Equal aspect ratio ensures a circle
@@ -186,8 +162,9 @@ def plot_emotion_barplot(heatmap_data):
186
  emotion_counts = most_probable_emotions.value_counts()
187
  all_emotions = heatmap_data.index
188
  emotion_frequencies = (emotion_counts.reindex(all_emotions, fill_value=0) / emotion_counts.sum()).sort_values(ascending=False)
 
189
  fig, ax = plt.subplots(figsize=(8, 6))
190
- sns.barplot(x=emotion_frequencies.values, y=emotion_frequencies.index, palette="coolwarm", ax=ax)
191
  ax.set_title("Relative Frequencies of Predicted Emotions")
192
  ax.set_xlabel("Relative Frequency")
193
  ax.set_ylabel("Emotions")
 
31
  4: "Joy",
32
  5: "None of Them"
33
  }
34
+
35
+ emotion_colors = {
36
+ "Anger": "#D96459",
37
+ "Fear": "#6A8EAE",
38
+ "Disgust": "#A4C639",
39
+ "Sadness": "#9DBCD4",
40
+ "Joy": "#F3E9A8",
41
+ "None of Them": "#C0C0C0"
42
+ }
43
  def load_spacy_model(model_name="xx_sent_ud_sm"):
44
  try:
45
  model = spacy.load(model_name)
 
126
 
127
  return fig
128
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
 
130
  def plot_average_emotion_pie(heatmap_data):
131
  all_emotion_scores = np.array([item['emotions'] for item in heatmap_data])
 
148
  labels=labels_filtered,
149
  autopct='%1.1f%%',
150
  startangle=140,
151
+ textprops={'fontsize': 12},
152
+ colors=[emotion_colors[l] for l in labels_filtered]
153
  )
154
 
155
  ax.axis('equal') # Equal aspect ratio ensures a circle
 
162
  emotion_counts = most_probable_emotions.value_counts()
163
  all_emotions = heatmap_data.index
164
  emotion_frequencies = (emotion_counts.reindex(all_emotions, fill_value=0) / emotion_counts.sum()).sort_values(ascending=False)
165
+ palette = [emotion_colors[emotion] for emotion in emotion_frequencies.index]
166
  fig, ax = plt.subplots(figsize=(8, 6))
167
+ sns.barplot(x=emotion_frequencies.values, y=emotion_frequencies.index, palette=palette, ax=ax)
168
  ax.set_title("Relative Frequencies of Predicted Emotions")
169
  ax.set_xlabel("Relative Frequency")
170
  ax.set_ylabel("Emotions")