Spaces:
Runtime error
Runtime error
Update visualization.py
Browse files- visualization.py +64 -81
visualization.py
CHANGED
|
@@ -1,91 +1,74 @@
|
|
| 1 |
-
import plotly.
|
| 2 |
-
|
| 3 |
-
def create_placeholder_chart(title="Error"):
|
| 4 |
-
fig = go.Figure()
|
| 5 |
-
fig.add_annotation(text="Error generating chart", xref="paper", yref="paper", showarrow=False, font=dict(size=20, color="red"))
|
| 6 |
-
fig.update_layout(title=title)
|
| 7 |
-
return fig
|
| 8 |
|
| 9 |
def create_charts(results):
|
| 10 |
charts = {}
|
| 11 |
explanations = {}
|
| 12 |
|
| 13 |
-
for
|
| 14 |
-
charts[
|
| 15 |
-
explanations[
|
| 16 |
|
| 17 |
# Attachment Styles
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
explanations[i]['attachment'] = f"Error in attachment data: {str(e)}"
|
| 32 |
-
|
| 33 |
-
# Attachment Dimensions (Radar Chart)
|
| 34 |
-
try:
|
| 35 |
-
dimensions_data = speaker_data['attachment_styles']
|
| 36 |
-
labels = ['Self', 'Others', 'Anxiety', 'Avoidance']
|
| 37 |
-
values = [dimensions_data[label] for label in labels]
|
| 38 |
-
|
| 39 |
-
fig = go.Figure(data=go.Scatterpolar(
|
| 40 |
-
r=values,
|
| 41 |
-
theta=labels,
|
| 42 |
-
fill='toself'
|
| 43 |
-
))
|
| 44 |
-
fig.update_layout(
|
| 45 |
-
polar=dict(
|
| 46 |
-
radialaxis=dict(visible=True, range=[0, 10])
|
| 47 |
-
),
|
| 48 |
-
showlegend=False,
|
| 49 |
-
title=f'Speaker {i+1}: Attachment Dimensions'
|
| 50 |
-
)
|
| 51 |
-
|
| 52 |
-
charts[i]['dimensions'] = fig
|
| 53 |
-
except Exception as e:
|
| 54 |
-
charts[i]['dimensions'] = create_placeholder_chart(f'Speaker {i+1}: Attachment Dimensions')
|
| 55 |
-
|
| 56 |
# Big Five Traits
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
charts[i]['bigfive'] = create_placeholder_chart(f'Speaker {i+1}: Big Five Traits')
|
| 69 |
-
explanations[i]['bigfive'] = f"Error in big five data: {str(e)}"
|
| 70 |
-
|
| 71 |
# Personality Disorders
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
except Exception as e:
|
| 87 |
-
charts[i]['personality'] = create_placeholder_chart(f'Speaker {i+1}: Personality Disorders')
|
| 88 |
-
explanations[i]['personality'] = f"Error in personality data: {str(e)}"
|
| 89 |
-
|
| 90 |
-
return charts, explanations
|
| 91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import plotly.graph_objs as go
|
| 2 |
+
from plotly.subplots import make_subplots
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
def create_charts(results):
|
| 5 |
charts = {}
|
| 6 |
explanations = {}
|
| 7 |
|
| 8 |
+
for speaker_id, data in results.items():
|
| 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']
|
| 15 |
+
values = [getattr(attachment_data, 'Secured', 0),
|
| 16 |
+
getattr(attachment_data, 'Anxious_Preoccupied', 0),
|
| 17 |
+
getattr(attachment_data, 'Dismissive_Avoidant', 0),
|
| 18 |
+
getattr(attachment_data, 'Fearful_Avoidant', 0)]
|
| 19 |
+
colors = ['blue', 'orange', 'green', 'red']
|
| 20 |
+
|
| 21 |
+
fig = go.Figure(data=[go.Bar(x=labels, y=values, marker_color=colors)])
|
| 22 |
+
fig.update_layout(title=f'{speaker_id}: Attachment Styles', yaxis_range=[0, 1])
|
| 23 |
+
charts[speaker_id]['attachment'] = fig
|
| 24 |
+
explanations[speaker_id]['attachment'] = attachment_data.Explanation
|
| 25 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
# Big Five Traits
|
| 27 |
+
bigfive_data = data['bigfive']
|
| 28 |
+
labels = ['Extraversion', 'Agreeableness', 'Conscientiousness', 'Neuroticism', 'Openness']
|
| 29 |
+
values = [bigfive_data.Extraversion, bigfive_data.Agreeableness,
|
| 30 |
+
bigfive_data.Conscientiousness, bigfive_data.Neuroticism, bigfive_data.Openness]
|
| 31 |
+
colors = ['blue', 'green', 'red', 'purple', 'orange']
|
| 32 |
+
|
| 33 |
+
fig = go.Figure(data=[go.Bar(x=labels, y=values, marker_color=colors)])
|
| 34 |
+
fig.update_layout(title=f'{speaker_id}: Big Five Traits', yaxis_range=[0, 10])
|
| 35 |
+
charts[speaker_id]['bigfive'] = fig
|
| 36 |
+
explanations[speaker_id]['bigfive'] = bigfive_data.Explanation
|
| 37 |
+
|
|
|
|
|
|
|
|
|
|
| 38 |
# Personality Disorders
|
| 39 |
+
personality_data = data['personalities']
|
| 40 |
+
labels = ['Antisocial', 'Narcissistic', 'Depressed', 'Anxious-Avoidant',
|
| 41 |
+
'Obsessive', 'Paranoid', 'Borderline', 'Dependent', 'Schizoid-Schizotypal']
|
| 42 |
+
values = [personality_data.Antisocial_Psychopathic, personality_data.Narcissistic,
|
| 43 |
+
personality_data.Depressed, personality_data.Anxious_Avoidant,
|
| 44 |
+
personality_data.Obsessional, personality_data.Paranoid,
|
| 45 |
+
personality_data.Borderline_Dysregulated, personality_data.Dependent_Victimized,
|
| 46 |
+
personality_data.Schizoid_Schizotypal]
|
| 47 |
+
colors = ['black', 'orange', 'gray', 'green', 'brown', 'purple', 'red', 'cyan', 'gold']
|
| 48 |
+
|
| 49 |
+
fig = go.Figure(data=[go.Bar(x=labels, y=values, marker_color=colors)])
|
| 50 |
+
fig.update_layout(title=f'{speaker_id}: Personality Disorders', yaxis_range=[0, 5])
|
| 51 |
+
charts[speaker_id]['personality'] = fig
|
| 52 |
+
explanations[speaker_id]['personality'] = personality_data.Explanation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
+
# Attachment Dimensions (Radar Chart)
|
| 55 |
+
dimensions_data = data['attachments']
|
| 56 |
+
labels = ['Self', 'Others', 'Anxiety', 'Avoidance']
|
| 57 |
+
values = [dimensions_data.Self, dimensions_data.Others,
|
| 58 |
+
dimensions_data.Anxiety, dimensions_data.Avoidance]
|
| 59 |
+
|
| 60 |
+
fig = go.Figure(data=go.Scatterpolar(
|
| 61 |
+
r=values,
|
| 62 |
+
theta=labels,
|
| 63 |
+
fill='toself'
|
| 64 |
+
))
|
| 65 |
+
fig.update_layout(
|
| 66 |
+
polar=dict(
|
| 67 |
+
radialaxis=dict(visible=True, range=[0, 10])
|
| 68 |
+
),
|
| 69 |
+
showlegend=False,
|
| 70 |
+
title=f'{speaker_id}: Attachment Dimensions'
|
| 71 |
+
)
|
| 72 |
+
charts[speaker_id]['dimensions'] = fig
|
| 73 |
+
|
| 74 |
+
return charts, explanations
|