Update app.py
Browse files
app.py
CHANGED
@@ -662,7 +662,7 @@ def analyze_emotions(text):
|
|
662 |
def create_visualization(result):
|
663 |
"""Create visualization of emotion analysis results"""
|
664 |
# Create figure and axis
|
665 |
-
fig, ax = plt.subplots(figsize=(
|
666 |
|
667 |
# Extract emotion data
|
668 |
emotions = [e[0] for e in result['emotion_scores']]
|
@@ -671,36 +671,39 @@ def create_visualization(result):
|
|
671 |
# Get colors
|
672 |
colors = [EMOTION_COLORS.get(emotion, '#CCCCCC') for emotion in emotions]
|
673 |
|
674 |
-
# Create bar chart
|
675 |
-
bars = ax.
|
|
|
|
|
|
|
|
|
|
|
676 |
|
677 |
# Add title and labels
|
678 |
ax.set_title('Emotion Analysis', fontsize=16, fontweight='bold')
|
679 |
-
ax.
|
680 |
-
ax.
|
681 |
|
682 |
-
# Add verdict as text annotation
|
683 |
verdict = result['emotional_verdict']['label']
|
684 |
description = result['emotional_verdict']['description']
|
685 |
-
ax.text(0.5, -0.
|
686 |
-
ax.text(0.5, -0.
|
687 |
-
|
688 |
-
# Rotate x-axis labels for readability
|
689 |
-
plt.xticks(rotation=45, ha='right')
|
690 |
|
691 |
# Add value labels on top of bars
|
692 |
for bar in bars:
|
693 |
-
|
694 |
-
ax.text(bar.
|
695 |
-
f'{
|
696 |
|
697 |
# Adjust layout
|
698 |
plt.tight_layout()
|
699 |
-
plt.subplots_adjust(bottom=0.
|
700 |
|
701 |
# Return figure
|
702 |
return fig
|
703 |
|
|
|
704 |
def analyze_text(text):
|
705 |
"""Analyze text and return visualization and detailed results"""
|
706 |
fig, result = analyze_emotions(text)
|
|
|
662 |
def create_visualization(result):
|
663 |
"""Create visualization of emotion analysis results"""
|
664 |
# Create figure and axis
|
665 |
+
fig, ax = plt.subplots(figsize=(12, 8))
|
666 |
|
667 |
# Extract emotion data
|
668 |
emotions = [e[0] for e in result['emotion_scores']]
|
|
|
671 |
# Get colors
|
672 |
colors = [EMOTION_COLORS.get(emotion, '#CCCCCC') for emotion in emotions]
|
673 |
|
674 |
+
# Create horizontal bar chart
|
675 |
+
bars = ax.barh(emotions, scores, color=colors)
|
676 |
+
|
677 |
+
# Set x-axis to a static 100%
|
678 |
+
ax.set_xlim(0, 100)
|
679 |
+
ax.set_xticks(range(0, 101, 10))
|
680 |
+
ax.set_xticklabels([f'{i}%' for i in range(0, 101, 10)])
|
681 |
|
682 |
# Add title and labels
|
683 |
ax.set_title('Emotion Analysis', fontsize=16, fontweight='bold')
|
684 |
+
ax.set_ylabel('Emotions', fontsize=12)
|
685 |
+
ax.set_xlabel('Score (%)', fontsize=12)
|
686 |
|
687 |
+
# Add verdict as text annotation below the chart
|
688 |
verdict = result['emotional_verdict']['label']
|
689 |
description = result['emotional_verdict']['description']
|
690 |
+
ax.text(0.5, -0.2, f"Verdict: {verdict}", ha='center', transform=ax.transAxes, fontsize=14, fontweight='bold')
|
691 |
+
ax.text(0.5, -0.27, f"{description}", ha='center', transform=ax.transAxes, fontsize=12)
|
|
|
|
|
|
|
692 |
|
693 |
# Add value labels on top of bars
|
694 |
for bar in bars:
|
695 |
+
width = bar.get_width()
|
696 |
+
ax.text(width + 0.5, bar.get_y() + bar.get_height() / 2,
|
697 |
+
f'{width:.1f}%', ha='left', va='center', fontsize=10)
|
698 |
|
699 |
# Adjust layout
|
700 |
plt.tight_layout()
|
701 |
+
plt.subplots_adjust(bottom=0.3) # Make room for the verdict text
|
702 |
|
703 |
# Return figure
|
704 |
return fig
|
705 |
|
706 |
+
|
707 |
def analyze_text(text):
|
708 |
"""Analyze text and return visualization and detailed results"""
|
709 |
fig, result = analyze_emotions(text)
|