Spaces:
Sleeping
Sleeping
vickeee465
commited on
Commit
·
9f339a6
1
Parent(s):
e4fa6a2
replaced sunburst chart with piechart
Browse files
app.py
CHANGED
|
@@ -151,6 +151,36 @@ def plot_sunburst_chart(heatmap_data):
|
|
| 151 |
|
| 152 |
return fig
|
| 153 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
def plot_emotion_barplot(heatmap_data):
|
| 155 |
most_probable_emotions = heatmap_data.idxmax(axis=0)
|
| 156 |
emotion_counts = most_probable_emotions.value_counts()
|
|
@@ -185,8 +215,9 @@ def predict_wrapper(text, language):
|
|
| 185 |
|
| 186 |
figure = plot_emotion_barplot(prepare_heatmap_data(results_heatmap))
|
| 187 |
heatmap = plot_emotion_heatmap(prepare_heatmap_data(results_heatmap))
|
|
|
|
| 188 |
output_info = f'Prediction was made using the <a href="https://huggingface.co/{model_id}">{model_id}</a> model.'
|
| 189 |
-
return results, figure,
|
| 190 |
|
| 191 |
|
| 192 |
with gr.Blocks() as demo:
|
|
@@ -210,7 +241,7 @@ with gr.Blocks() as demo:
|
|
| 210 |
plot = gr.Plot()
|
| 211 |
|
| 212 |
with gr.Row():
|
| 213 |
-
|
| 214 |
|
| 215 |
with gr.Row():
|
| 216 |
heatmap = gr.Plot()
|
|
@@ -221,7 +252,7 @@ with gr.Blocks() as demo:
|
|
| 221 |
predict_button.click(
|
| 222 |
fn=predict_wrapper,
|
| 223 |
inputs=[input_text, language_choice],
|
| 224 |
-
outputs=[result_table, plot,
|
| 225 |
)
|
| 226 |
|
| 227 |
if __name__ == "__main__":
|
|
|
|
| 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])
|
| 157 |
+
mean_scores = all_emotion_scores.mean(axis=0)
|
| 158 |
+
|
| 159 |
+
labels = [id2label[i] for i in range(len(mean_scores))]
|
| 160 |
+
sizes = mean_scores
|
| 161 |
+
|
| 162 |
+
# optional: remove emotions with near-zero average
|
| 163 |
+
labels_filtered = []
|
| 164 |
+
sizes_filtered = []
|
| 165 |
+
for l, s in zip(labels, sizes):
|
| 166 |
+
if s > 0.01: # You can change this threshold
|
| 167 |
+
labels_filtered.append(l)
|
| 168 |
+
sizes_filtered.append(s)
|
| 169 |
+
|
| 170 |
+
fig, ax = plt.subplots(figsize=(6, 6))
|
| 171 |
+
wedges, texts, autotexts = ax.pie(
|
| 172 |
+
sizes_filtered,
|
| 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
|
| 180 |
+
plt.title("Average Emotion Confidence Across Sentences", fontsize=14)
|
| 181 |
+
|
| 182 |
+
return fig
|
| 183 |
+
|
| 184 |
def plot_emotion_barplot(heatmap_data):
|
| 185 |
most_probable_emotions = heatmap_data.idxmax(axis=0)
|
| 186 |
emotion_counts = most_probable_emotions.value_counts()
|
|
|
|
| 215 |
|
| 216 |
figure = plot_emotion_barplot(prepare_heatmap_data(results_heatmap))
|
| 217 |
heatmap = plot_emotion_heatmap(prepare_heatmap_data(results_heatmap))
|
| 218 |
+
piechart = plot_average_emotion_pie(prepare_heatmap_data(results_heatmap))
|
| 219 |
output_info = f'Prediction was made using the <a href="https://huggingface.co/{model_id}">{model_id}</a> model.'
|
| 220 |
+
return results, figure, piechart, heatmap, output_info
|
| 221 |
|
| 222 |
|
| 223 |
with gr.Blocks() as demo:
|
|
|
|
| 241 |
plot = gr.Plot()
|
| 242 |
|
| 243 |
with gr.Row():
|
| 244 |
+
piechart = gr.Plot()
|
| 245 |
|
| 246 |
with gr.Row():
|
| 247 |
heatmap = gr.Plot()
|
|
|
|
| 252 |
predict_button.click(
|
| 253 |
fn=predict_wrapper,
|
| 254 |
inputs=[input_text, language_choice],
|
| 255 |
+
outputs=[result_table, plot, piechart, heatmap, model_info]
|
| 256 |
)
|
| 257 |
|
| 258 |
if __name__ == "__main__":
|