kambris commited on
Commit
cae4daa
·
verified ·
1 Parent(s): 3dca961

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -27
app.py CHANGED
@@ -299,7 +299,6 @@ def process_all_analyses(text, _analyzer):
299
  return segments, segment_labels, sentiment_scores, basic_emotions, moral_trajectories
300
 
301
 
302
- return segments, segment_labels, sentiment_scores, basic_emotions, moral_trajectories
303
  def main():
304
  st.title("🗣️ Political Text Analysis Toolkit")
305
 
@@ -399,40 +398,34 @@ def main():
399
  line=dict(color=colors[idx], width=2),
400
  marker=dict(size=6)
401
  ))
402
-
403
  if "Basic Emotions Flow" in viz_options:
404
  emotions_df = pd.DataFrame({
405
  'Segment': segment_labels,
406
  'Emotion': basic_emotions
407
  })
 
 
 
 
 
 
 
 
 
 
 
408
  unified_fig.add_trace(go.Bar(
409
  x=segment_labels,
410
- y=[1 if e == 'joy' else 0.5 if e == 'neutral' else -0.5 for e in basic_emotions],
411
- name=f'Emotions ({", ".join(set(basic_emotions))})',
412
- marker_color='#2ecc71',
413
- opacity=0.6,
414
- hovertemplate="Segment: %{x}<br>Emotion: " +
415
- "<br>".join([f"{e}" for e in basic_emotions]) +
416
- "<extra></extra>"
 
417
  ))
418
-
419
- unified_fig.update_layout(
420
- title='Speech Analysis Flow',
421
- xaxis_title='Speech Segments',
422
- yaxis_title='Analysis Values',
423
- plot_bgcolor='white',
424
- height=600,
425
- showlegend=True,
426
- legend=dict(
427
- orientation="h",
428
- yanchor="bottom",
429
- y=1.02,
430
- xanchor="right",
431
- x=1
432
- ),
433
- hovermode='x unified'
434
- )
435
-
436
  st.plotly_chart(unified_fig, use_container_width=True)
437
 
438
  with tab3:
 
299
  return segments, segment_labels, sentiment_scores, basic_emotions, moral_trajectories
300
 
301
 
 
302
  def main():
303
  st.title("🗣️ Political Text Analysis Toolkit")
304
 
 
398
  line=dict(color=colors[idx], width=2),
399
  marker=dict(size=6)
400
  ))
 
401
  if "Basic Emotions Flow" in viz_options:
402
  emotions_df = pd.DataFrame({
403
  'Segment': segment_labels,
404
  'Emotion': basic_emotions
405
  })
406
+
407
+ # Create color mapping for emotions
408
+ emotion_colors = {
409
+ 'joy': '#FFD700', # Gold
410
+ 'sadness': '#4169E1', # Royal Blue
411
+ 'anger': '#FF4500', # Red Orange
412
+ 'fear': '#800080', # Purple
413
+ 'disgust': '#006400', # Dark Green
414
+ 'surprise': '#FFA500' # Orange
415
+ }
416
+
417
  unified_fig.add_trace(go.Bar(
418
  x=segment_labels,
419
+ y=[1] * len(basic_emotions), # Full height bars
420
+ name='Basic Emotions',
421
+ marker=dict(
422
+ color=[emotion_colors.get(e.lower(), '#808080') for e in basic_emotions]
423
+ ),
424
+ opacity=0.8,
425
+ hovertemplate="Segment: %{x}<br>Emotion: %{text}<extra></extra>",
426
+ text=basic_emotions
427
  ))
428
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
429
  st.plotly_chart(unified_fig, use_container_width=True)
430
 
431
  with tab3: