Spaces:
Runtime error
Runtime error
Update visualization.py
Browse files- visualization.py +12 -12
visualization.py
CHANGED
@@ -9,8 +9,9 @@ def extract_data_and_explanation(text):
|
|
9 |
line = line.strip()
|
10 |
if line.startswith("-------"):
|
11 |
if current_speaker and explanation:
|
12 |
-
speakers_data[current_speaker]["explanation"] = explanation
|
13 |
explanation = ""
|
|
|
14 |
continue
|
15 |
if line.startswith("Speaker"):
|
16 |
current_speaker = line.split(':')[0].strip()
|
@@ -20,7 +21,7 @@ def extract_data_and_explanation(text):
|
|
20 |
key = key.strip()
|
21 |
value = value.strip()
|
22 |
if key.lower() == "explanation":
|
23 |
-
explanation
|
24 |
elif '|' in value:
|
25 |
for part in value.split('|'):
|
26 |
part = part.strip()
|
@@ -32,20 +33,17 @@ def extract_data_and_explanation(text):
|
|
32 |
sub_key, sub_value = parts
|
33 |
else:
|
34 |
continue
|
35 |
-
|
36 |
-
speakers_data[current_speaker][sub_key.strip()] = float(sub_value.strip())
|
37 |
-
except ValueError:
|
38 |
-
speakers_data[current_speaker][sub_key.strip()] = sub_value.strip()
|
39 |
else:
|
40 |
try:
|
41 |
speakers_data[current_speaker][key] = float(value)
|
42 |
except ValueError:
|
43 |
speakers_data[current_speaker][key] = value
|
44 |
elif line and current_speaker:
|
45 |
-
|
46 |
|
47 |
if current_speaker and explanation:
|
48 |
-
speakers_data[current_speaker]["explanation"] = explanation
|
49 |
|
50 |
return speakers_data
|
51 |
|
@@ -53,9 +51,12 @@ def create_bar_chart(data, title):
|
|
53 |
fig = go.Figure(data=[go.Bar(
|
54 |
x=list(data.keys()),
|
55 |
y=list(data.values()),
|
|
|
|
|
56 |
marker_color=['red', 'green', 'blue', 'yellow', 'purple', 'orange', 'pink', 'cyan', 'magenta', 'brown'][:len(data)]
|
57 |
)])
|
58 |
fig.update_layout(title=title, xaxis_title="Traits", yaxis_title="Score")
|
|
|
59 |
return fig
|
60 |
|
61 |
def create_radar_chart(data, title):
|
@@ -86,15 +87,15 @@ def update_visibility_and_charts(status, exec_time, lang, attachments, bigfive,
|
|
86 |
for speaker, data in speakers_data.items():
|
87 |
if data:
|
88 |
if analysis_type == "Attachments":
|
89 |
-
chart_data = {k: v for k, v in data.items() if k in ["Secured", "Anxious-Preoccupied", "Dismissive-Avoidant", "Fearful-Avoidant"]}
|
90 |
if chart_data:
|
91 |
fig = create_bar_chart(chart_data, f"{analysis_type} Analysis - {speaker}")
|
92 |
outputs.append(gr.update(value=fig, visible=True))
|
93 |
else:
|
94 |
outputs.append(gr.update(visible=False))
|
95 |
|
96 |
-
radar_data = {k: v for k, v in data.items() if k in ["Anxiety", "Avoidance", "Self", "Others"]}
|
97 |
-
if
|
98 |
radar_fig = create_radar_chart(radar_data, f"Anxiety-Avoidance-Self-Others - {speaker}")
|
99 |
outputs.append(gr.update(value=radar_fig, visible=True))
|
100 |
else:
|
@@ -116,5 +117,4 @@ def update_visibility_and_charts(status, exec_time, lang, attachments, bigfive,
|
|
116 |
while len(outputs) < 21:
|
117 |
outputs.append(gr.update(visible=False))
|
118 |
|
119 |
-
print("Outputs generated:", outputs)
|
120 |
return outputs
|
|
|
9 |
line = line.strip()
|
10 |
if line.startswith("-------"):
|
11 |
if current_speaker and explanation:
|
12 |
+
speakers_data[current_speaker]["explanation"] = explanation.strip()
|
13 |
explanation = ""
|
14 |
+
current_speaker = None
|
15 |
continue
|
16 |
if line.startswith("Speaker"):
|
17 |
current_speaker = line.split(':')[0].strip()
|
|
|
21 |
key = key.strip()
|
22 |
value = value.strip()
|
23 |
if key.lower() == "explanation":
|
24 |
+
explanation += value + " "
|
25 |
elif '|' in value:
|
26 |
for part in value.split('|'):
|
27 |
part = part.strip()
|
|
|
33 |
sub_key, sub_value = parts
|
34 |
else:
|
35 |
continue
|
36 |
+
speakers_data[current_speaker][sub_key.strip()] = float(sub_value.strip())
|
|
|
|
|
|
|
37 |
else:
|
38 |
try:
|
39 |
speakers_data[current_speaker][key] = float(value)
|
40 |
except ValueError:
|
41 |
speakers_data[current_speaker][key] = value
|
42 |
elif line and current_speaker:
|
43 |
+
explanation += line + " "
|
44 |
|
45 |
if current_speaker and explanation:
|
46 |
+
speakers_data[current_speaker]["explanation"] = explanation.strip()
|
47 |
|
48 |
return speakers_data
|
49 |
|
|
|
51 |
fig = go.Figure(data=[go.Bar(
|
52 |
x=list(data.keys()),
|
53 |
y=list(data.values()),
|
54 |
+
text=list(data.values()),
|
55 |
+
textposition='auto',
|
56 |
marker_color=['red', 'green', 'blue', 'yellow', 'purple', 'orange', 'pink', 'cyan', 'magenta', 'brown'][:len(data)]
|
57 |
)])
|
58 |
fig.update_layout(title=title, xaxis_title="Traits", yaxis_title="Score")
|
59 |
+
fig.update_xaxes(tickangle=45)
|
60 |
return fig
|
61 |
|
62 |
def create_radar_chart(data, title):
|
|
|
87 |
for speaker, data in speakers_data.items():
|
88 |
if data:
|
89 |
if analysis_type == "Attachments":
|
90 |
+
chart_data = {k: v for k, v in data.items() if k in ["Secured", "Anxious-Preoccupied", "Dismissive-Avoidant", "Fearful-Avoidant"] and isinstance(v, (int, float))}
|
91 |
if chart_data:
|
92 |
fig = create_bar_chart(chart_data, f"{analysis_type} Analysis - {speaker}")
|
93 |
outputs.append(gr.update(value=fig, visible=True))
|
94 |
else:
|
95 |
outputs.append(gr.update(visible=False))
|
96 |
|
97 |
+
radar_data = {k: v for k, v in data.items() if k in ["Anxiety", "Avoidance", "Self", "Others"] and isinstance(v, (int, float))}
|
98 |
+
if radar_data:
|
99 |
radar_fig = create_radar_chart(radar_data, f"Anxiety-Avoidance-Self-Others - {speaker}")
|
100 |
outputs.append(gr.update(value=radar_fig, visible=True))
|
101 |
else:
|
|
|
117 |
while len(outputs) < 21:
|
118 |
outputs.append(gr.update(visible=False))
|
119 |
|
|
|
120 |
return outputs
|