Spaces:
Runtime error
Runtime error
Update visualization.py
Browse files- visualization.py +33 -18
visualization.py
CHANGED
|
@@ -9,6 +9,9 @@ def create_charts(results):
|
|
| 9 |
charts[speaker_id] = {}
|
| 10 |
explanations[speaker_id] = {}
|
| 11 |
|
|
|
|
|
|
|
|
|
|
| 12 |
# Attachment Styles
|
| 13 |
attachment_data = data['attachments']
|
| 14 |
labels = ['Secured', 'Anxious-Preoccupied', 'Dismissive-Avoidant', 'Fearful-Avoidant']
|
|
@@ -16,9 +19,10 @@ def create_charts(results):
|
|
| 16 |
getattr(attachment_data, 'Anxious_Preoccupied', 0),
|
| 17 |
getattr(attachment_data, 'Dismissive_Avoidant', 0),
|
| 18 |
getattr(attachment_data, 'Fearful_Avoidant', 0)]
|
|
|
|
| 19 |
|
| 20 |
-
fig = go.Figure(data=[go.Bar(x=labels, y=values)])
|
| 21 |
-
fig.update_layout(title=f'Attachment Styles
|
| 22 |
charts[speaker_id]['attachment'] = fig
|
| 23 |
explanations[speaker_id]['attachment'] = attachment_data.Explanation
|
| 24 |
|
|
@@ -27,36 +31,47 @@ def create_charts(results):
|
|
| 27 |
labels = ['Extraversion', 'Agreeableness', 'Conscientiousness', 'Neuroticism', 'Openness']
|
| 28 |
values = [bigfive_data.Extraversion, bigfive_data.Agreeableness,
|
| 29 |
bigfive_data.Conscientiousness, bigfive_data.Neuroticism, bigfive_data.Openness]
|
|
|
|
| 30 |
|
| 31 |
-
fig = go.Figure(data=[go.Bar(x=labels, y=values)])
|
| 32 |
-
fig.update_layout(title=f'Big Five Traits
|
| 33 |
charts[speaker_id]['bigfive'] = fig
|
| 34 |
explanations[speaker_id]['bigfive'] = bigfive_data.Explanation
|
| 35 |
|
| 36 |
# Personality Disorders
|
| 37 |
personality_data = data['personalities']
|
| 38 |
-
labels = ['
|
| 39 |
-
'Borderline
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
personality_data.
|
| 43 |
-
personality_data.Borderline_Dysregulated, personality_data.
|
| 44 |
-
personality_data.
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
fig = go.Figure(data=[go.Bar(x=labels, y=values)])
|
| 48 |
-
fig.update_layout(title=f'Personality Disorders
|
| 49 |
charts[speaker_id]['personality'] = fig
|
| 50 |
explanations[speaker_id]['personality'] = personality_data.Explanation
|
| 51 |
|
| 52 |
-
# Dimensions
|
| 53 |
dimensions_data = data['attachments']
|
| 54 |
labels = ['Self', 'Others', 'Anxiety', 'Avoidance']
|
| 55 |
values = [dimensions_data.Self, dimensions_data.Others,
|
| 56 |
dimensions_data.Anxiety, dimensions_data.Avoidance]
|
| 57 |
|
| 58 |
-
fig = go.Figure(data=
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
charts[speaker_id]['dimensions'] = fig
|
| 61 |
|
| 62 |
return charts, explanations
|
|
|
|
| 9 |
charts[speaker_id] = {}
|
| 10 |
explanations[speaker_id] = {}
|
| 11 |
|
| 12 |
+
# Extract the actual name from the speaker_id
|
| 13 |
+
speaker_name = speaker_id.split(": ", 1)[-1]
|
| 14 |
+
|
| 15 |
# Attachment Styles
|
| 16 |
attachment_data = data['attachments']
|
| 17 |
labels = ['Secured', 'Anxious-Preoccupied', 'Dismissive-Avoidant', 'Fearful-Avoidant']
|
|
|
|
| 19 |
getattr(attachment_data, 'Anxious_Preoccupied', 0),
|
| 20 |
getattr(attachment_data, 'Dismissive_Avoidant', 0),
|
| 21 |
getattr(attachment_data, 'Fearful_Avoidant', 0)]
|
| 22 |
+
colors = ['blue', 'orange', 'green', 'red']
|
| 23 |
|
| 24 |
+
fig = go.Figure(data=[go.Bar(x=labels, y=values, marker_color=colors)])
|
| 25 |
+
fig.update_layout(title=f'Attachment Styles: {speaker_name}', yaxis_range=[0, 1])
|
| 26 |
charts[speaker_id]['attachment'] = fig
|
| 27 |
explanations[speaker_id]['attachment'] = attachment_data.Explanation
|
| 28 |
|
|
|
|
| 31 |
labels = ['Extraversion', 'Agreeableness', 'Conscientiousness', 'Neuroticism', 'Openness']
|
| 32 |
values = [bigfive_data.Extraversion, bigfive_data.Agreeableness,
|
| 33 |
bigfive_data.Conscientiousness, bigfive_data.Neuroticism, bigfive_data.Openness]
|
| 34 |
+
colors = ['blue', 'green', 'red', 'purple', 'orange']
|
| 35 |
|
| 36 |
+
fig = go.Figure(data=[go.Bar(x=labels, y=values, marker_color=colors)])
|
| 37 |
+
fig.update_layout(title=f'Big Five Traits: {speaker_name}', yaxis_range=[0, 10])
|
| 38 |
charts[speaker_id]['bigfive'] = fig
|
| 39 |
explanations[speaker_id]['bigfive'] = bigfive_data.Explanation
|
| 40 |
|
| 41 |
# Personality Disorders
|
| 42 |
personality_data = data['personalities']
|
| 43 |
+
labels = ['Antisocial', 'Narcissistic', 'Depressed', 'Anxious-Avoidant',
|
| 44 |
+
'Obsessive', 'Paranoid', 'Borderline', 'Dependent', 'Schizoid-Schizotypal']
|
| 45 |
+
values = [personality_data.Antisocial_Psychopathic, personality_data.Narcissistic,
|
| 46 |
+
personality_data.Depressed, personality_data.Anxious_Avoidant,
|
| 47 |
+
personality_data.Obsessional, personality_data.Paranoid,
|
| 48 |
+
personality_data.Borderline_Dysregulated, personality_data.Dependent_Victimized,
|
| 49 |
+
personality_data.Schizoid_Schizotypal]
|
| 50 |
+
colors = ['black', 'orange', 'gray', 'green', 'brown', 'purple', 'red', 'cyan', 'gold']
|
| 51 |
+
|
| 52 |
+
fig = go.Figure(data=[go.Bar(x=labels, y=values, marker_color=colors)])
|
| 53 |
+
fig.update_layout(title=f'Personality Disorders: {speaker_name}', yaxis_range=[0, 5])
|
| 54 |
charts[speaker_id]['personality'] = fig
|
| 55 |
explanations[speaker_id]['personality'] = personality_data.Explanation
|
| 56 |
|
| 57 |
+
# Attachment Dimensions (Radar Chart)
|
| 58 |
dimensions_data = data['attachments']
|
| 59 |
labels = ['Self', 'Others', 'Anxiety', 'Avoidance']
|
| 60 |
values = [dimensions_data.Self, dimensions_data.Others,
|
| 61 |
dimensions_data.Anxiety, dimensions_data.Avoidance]
|
| 62 |
|
| 63 |
+
fig = go.Figure(data=go.Scatterpolar(
|
| 64 |
+
r=values,
|
| 65 |
+
theta=labels,
|
| 66 |
+
fill='toself'
|
| 67 |
+
))
|
| 68 |
+
fig.update_layout(
|
| 69 |
+
polar=dict(
|
| 70 |
+
radialaxis=dict(visible=True, range=[0, 10])
|
| 71 |
+
),
|
| 72 |
+
showlegend=False,
|
| 73 |
+
title=f'Attachment Dimensions: {speaker_name}'
|
| 74 |
+
)
|
| 75 |
charts[speaker_id]['dimensions'] = fig
|
| 76 |
|
| 77 |
return charts, explanations
|