Spaces:
Runtime error
Runtime error
Update visualization.py
Browse files- visualization.py +59 -59
visualization.py
CHANGED
@@ -5,70 +5,70 @@ def create_charts(results):
|
|
5 |
charts = {}
|
6 |
explanations = {}
|
7 |
|
8 |
-
speaker_id
|
9 |
-
|
10 |
-
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
|
74 |
return charts, explanations
|
|
|
5 |
charts = {}
|
6 |
explanations = {}
|
7 |
|
8 |
+
for speaker_id, speaker_data in results.items():
|
9 |
+
speaker_charts = {}
|
10 |
+
speaker_explanations = {}
|
11 |
|
12 |
+
# Attachment Styles
|
13 |
+
attachment_data = speaker_data.get('attachments')
|
14 |
+
if attachment_data:
|
15 |
+
fig_attachment = go.Figure(go.Bar(
|
16 |
+
x=['Secured', 'Anxious-Preoccupied', 'Dismissive-Avoidant', 'Fearful-Avoidant'],
|
17 |
+
y=[getattr(attachment_data, 'secured', 0), getattr(attachment_data, 'anxious_preoccupied', 0),
|
18 |
+
getattr(attachment_data, 'dismissive_avoidant', 0), getattr(attachment_data, 'fearful_avoidant', 0)],
|
19 |
+
marker_color=['blue', 'orange', 'green', 'red']
|
20 |
+
))
|
21 |
+
fig_attachment.update_layout(title_text=f"Attachment Styles - {speaker_id}", showlegend=False)
|
22 |
+
speaker_charts["attachment"] = fig_attachment
|
23 |
+
speaker_explanations["attachment"] = getattr(attachment_data, 'explanation', '')
|
24 |
|
25 |
+
# Attachment Dimensions (Radar Chart)
|
26 |
+
fig_dimensions = go.Figure(go.Scatterpolar(
|
27 |
+
r=[getattr(attachment_data, 'avoidance', 0), getattr(attachment_data, 'anxiety', 0),
|
28 |
+
getattr(attachment_data, 'self_rating', 0), getattr(attachment_data, 'others_rating', 0)],
|
29 |
+
theta=['Avoidance', 'Anxiety', 'Self', 'Others'],
|
30 |
+
fill='toself'
|
31 |
+
))
|
32 |
+
fig_dimensions.update_layout(title_text=f"Attachment Dimensions - {speaker_id}", showlegend=False)
|
33 |
+
speaker_charts["dimensions"] = fig_dimensions
|
34 |
|
35 |
+
# Big Five Traits
|
36 |
+
bigfive_data = speaker_data.get('bigfive')
|
37 |
+
if bigfive_data:
|
38 |
+
fig_bigfive = go.Figure(go.Bar(
|
39 |
+
x=['Extraversion', 'Agreeableness', 'Conscientiousness', 'Neuroticism', 'Openness'],
|
40 |
+
y=[getattr(bigfive_data, 'extraversion', 0), getattr(bigfive_data, 'agreeableness', 0),
|
41 |
+
getattr(bigfive_data, 'conscientiousness', 0), getattr(bigfive_data, 'neuroticism', 0),
|
42 |
+
getattr(bigfive_data, 'openness', 0)],
|
43 |
+
marker_color=['blue', 'green', 'red', 'purple', 'orange']
|
44 |
+
))
|
45 |
+
fig_bigfive.update_layout(title_text=f"Big Five Traits - {speaker_id}", showlegend=False)
|
46 |
+
speaker_charts["bigfive"] = fig_bigfive
|
47 |
+
speaker_explanations["bigfive"] = getattr(bigfive_data, 'explanation', '')
|
48 |
|
49 |
+
# Personality Disorders
|
50 |
+
personality_data = speaker_data.get('personalities')
|
51 |
+
if personality_data:
|
52 |
+
fig_personality = go.Figure(go.Bar(
|
53 |
+
x=['Antisocial', 'Narcissistic', 'Depressed', 'Anxious-Avoidant',
|
54 |
+
'Obsessive', 'Paranoid', 'Borderline', 'Dependent', 'Schizoid-Schizotypal'],
|
55 |
+
y=[getattr(personality_data, 'antisocial_psychopathic', 0), getattr(personality_data, 'narcissistic', 0),
|
56 |
+
getattr(personality_data, 'depressed', 0), getattr(personality_data, 'anxious_avoidant', 0),
|
57 |
+
getattr(personality_data, 'obsessional', 0), getattr(personality_data, 'paranoid', 0),
|
58 |
+
getattr(personality_data, 'borderline_dysregulated', 0), getattr(personality_data, 'dependent_victimized', 0),
|
59 |
+
getattr(personality_data, 'schizoid_schizotypal', 0)],
|
60 |
+
marker_color=['black', 'orange', 'gray', 'green', 'brown', 'purple', 'red', 'cyan', 'magenta']
|
61 |
+
))
|
62 |
+
fig_personality.update_layout(title_text=f"Personality Disorders - {speaker_id}", showlegend=False)
|
63 |
+
speaker_charts["personality"] = fig_personality
|
64 |
+
speaker_explanations["personality"] = getattr(personality_data, 'explanation', '')
|
65 |
|
66 |
+
# Update all charts to take full width
|
67 |
+
for fig in speaker_charts.values():
|
68 |
+
fig.update_layout(height=400, width=None, margin=dict(l=50, r=50, t=100, b=50))
|
69 |
|
70 |
+
# Store the charts and explanations for each speaker
|
71 |
+
charts[speaker_id] = speaker_charts
|
72 |
+
explanations[speaker_id] = speaker_explanations
|
73 |
|
74 |
return charts, explanations
|