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