Spaces:
Runtime error
Runtime error
File size: 2,351 Bytes
50eb966 e449be6 50eb966 ec471fc 69443bf 2017ddc 69443bf ec471fc 3d45e40 69443bf 3d45e40 ec471fc 2017ddc 69443bf 3d45e40 e449be6 ec471fc 3d45e40 ec471fc 3d45e40 a9ba978 2017ddc 3d45e40 2017ddc 69443bf ece2104 fc582b2 ece2104 fc582b2 dee4bb0 0c982ed 9e1d300 2017ddc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
import gradio as gr
import plotly.graph_objs as go
import re
import json
def extract_data_and_explanation(text):
speakers_data = {}
current_speaker = None
explanation = ""
for line in text.split('\n'):
if line.startswith("Speaker"):
current_speaker = line.split(':')[0].strip()
speakers_data[current_speaker] = {}
elif ':' in line and current_speaker:
key, value = line.split(':', 1)
try:
speakers_data[current_speaker][key.strip()] = float(value.strip())
except ValueError:
pass
elif line.lower().startswith("explanation:"):
explanation = line.split("Explanation:", 1)[1].strip()
return speakers_data, explanation
def create_bar_chart(data, title):
fig = go.Figure(data=[go.Bar(
x=list(data.keys()),
y=list(data.values()),
marker_color=['red', 'green', 'blue', 'yellow', 'purple', 'orange', 'pink', 'cyan', 'magenta', 'brown'][:len(data)]
)])
fig.update_layout(title=title, xaxis_title="Traits", yaxis_title="Score")
return fig
def update_visibility_and_charts(status, exec_time, lang, attachments, bigfive, personalities):
outputs = [
gr.update(value=status, visible=True),
gr.update(value=exec_time, visible=True),
gr.update(value=lang, visible=True),
]
for analysis_text, analysis_type in [(attachments, "Attachments"), (bigfive, "Big Five"), (personalities, "Personalities")]:
speakers_data, explanation = extract_data_and_explanation(analysis_text)
for speaker, data in speakers_data.items():
if data:
fig = create_bar_chart(data, f"{analysis_type} Analysis - {speaker}")
outputs.append(gr.update(value=fig, visible=True))
outputs.append(gr.update(value=explanation, visible=True, label=f"{analysis_type} Explanation - {speaker}"))
else:
outputs.append(gr.update(visible=False))
outputs.append(gr.update(visible=False))
# Pad the outputs to ensure we always return the same number of outputs
while len(outputs) < 15: # 3 initial outputs + 6 plots + 6 explanations
outputs.append(gr.update(visible=False))
print("Outputs generated:", outputs)
return outputs |