Spaces:
Running
Running
vickeee465
commited on
Commit
·
d16db8d
1
Parent(s):
416f5a0
making it prettier
Browse files
app.py
CHANGED
@@ -105,25 +105,39 @@ def plot_sunburst_chart(heatmap_data):
|
|
105 |
for item in heatmap_data:
|
106 |
sentence = item['sentence']
|
107 |
emotions = item['emotions']
|
|
|
|
|
|
|
|
|
108 |
for i, score in enumerate(emotions):
|
109 |
data.append({
|
110 |
-
'
|
111 |
-
'sentence': sentence,
|
112 |
'emotion': id2label[i],
|
113 |
'score': float(score)
|
114 |
})
|
115 |
|
116 |
df = pd.DataFrame(data)
|
117 |
|
118 |
-
#
|
119 |
fig = px.sunburst(
|
120 |
df,
|
121 |
-
path=['
|
122 |
values='score',
|
123 |
color='emotion',
|
124 |
-
|
|
|
125 |
)
|
126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
return fig
|
128 |
|
129 |
def plot_emotion_barplot(heatmap_data):
|
|
|
105 |
for item in heatmap_data:
|
106 |
sentence = item['sentence']
|
107 |
emotions = item['emotions']
|
108 |
+
|
109 |
+
# Wrap long sentences for better display
|
110 |
+
sentence_wrapped = "\n".join([sentence[i:i + 50] for i in range(0, len(sentence), 50)])
|
111 |
+
|
112 |
for i, score in enumerate(emotions):
|
113 |
data.append({
|
114 |
+
'sentence': sentence_wrapped,
|
|
|
115 |
'emotion': id2label[i],
|
116 |
'score': float(score)
|
117 |
})
|
118 |
|
119 |
df = pd.DataFrame(data)
|
120 |
|
121 |
+
# Create sunburst chart (no "root" level)
|
122 |
fig = px.sunburst(
|
123 |
df,
|
124 |
+
path=['sentence', 'emotion'],
|
125 |
values='score',
|
126 |
color='emotion',
|
127 |
+
hover_data={'score': ':.3f'},
|
128 |
+
title='Sentence-Level Emotion Confidence Sunburst'
|
129 |
)
|
130 |
|
131 |
+
# Make the chart bigger
|
132 |
+
fig.update_layout(
|
133 |
+
width=800,
|
134 |
+
height=800,
|
135 |
+
margin=dict(t=50, l=0, r=0, b=0)
|
136 |
+
)
|
137 |
+
|
138 |
+
# Display the chart in Streamlit
|
139 |
+
st.plotly_chart(fig, use_container_width=True)
|
140 |
+
|
141 |
return fig
|
142 |
|
143 |
def plot_emotion_barplot(heatmap_data):
|