Spaces:
Runtime error
Runtime error
Update visualization.py
Browse files- visualization.py +15 -11
visualization.py
CHANGED
@@ -3,19 +3,22 @@ import plotly.graph_objs as go
|
|
3 |
import re
|
4 |
|
5 |
def extract_data_and_explanation(text):
|
6 |
-
|
|
|
7 |
explanation = ""
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
11 |
key, value = line.split(':', 1)
|
12 |
try:
|
13 |
-
|
14 |
except ValueError:
|
15 |
pass
|
16 |
elif line.lower().startswith("explanation:"):
|
17 |
explanation = line.split("Explanation:", 1)[1].strip()
|
18 |
-
return
|
19 |
|
20 |
def create_bar_chart(data, title):
|
21 |
fig = go.Figure(data=[go.Bar(
|
@@ -34,11 +37,12 @@ def update_visibility_and_charts(status, exec_time, lang, attachments, bigfive,
|
|
34 |
]
|
35 |
|
36 |
for analysis_text, analysis_type in [(attachments, "Attachments"), (bigfive, "Big Five"), (personalities, "Personalities")]:
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
|
|
42 |
|
43 |
print("Outputs generated:", outputs)
|
44 |
return outputs
|
|
|
3 |
import re
|
4 |
|
5 |
def extract_data_and_explanation(text):
|
6 |
+
speakers_data = {}
|
7 |
+
current_speaker = None
|
8 |
explanation = ""
|
9 |
+
for line in text.split('\n'):
|
10 |
+
if line.startswith("Speaker"):
|
11 |
+
current_speaker = line.split(':')[0].strip()
|
12 |
+
speakers_data[current_speaker] = {}
|
13 |
+
elif ':' in line and current_speaker:
|
14 |
key, value = line.split(':', 1)
|
15 |
try:
|
16 |
+
speakers_data[current_speaker][key.strip()] = float(value.strip())
|
17 |
except ValueError:
|
18 |
pass
|
19 |
elif line.lower().startswith("explanation:"):
|
20 |
explanation = line.split("Explanation:", 1)[1].strip()
|
21 |
+
return speakers_data, explanation
|
22 |
|
23 |
def create_bar_chart(data, title):
|
24 |
fig = go.Figure(data=[go.Bar(
|
|
|
37 |
]
|
38 |
|
39 |
for analysis_text, analysis_type in [(attachments, "Attachments"), (bigfive, "Big Five"), (personalities, "Personalities")]:
|
40 |
+
speakers_data, explanation = extract_data_and_explanation(analysis_text)
|
41 |
+
for speaker, data in speakers_data.items():
|
42 |
+
if data:
|
43 |
+
fig = create_bar_chart(data, f"{analysis_type} Analysis - {speaker}")
|
44 |
+
outputs.append(gr.Plot(value=fig))
|
45 |
+
outputs.append(gr.Textbox(value=explanation, label=f"{analysis_type} Explanation - {speaker}"))
|
46 |
|
47 |
print("Outputs generated:", outputs)
|
48 |
return outputs
|