Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,90 +2,13 @@ import gradio as gr
|
|
2 |
from llm_loader import load_model
|
3 |
from processing import process_input
|
4 |
from transcription_diarization import diarize_audio
|
|
|
5 |
import time
|
6 |
from config import openai_api_key
|
7 |
-
import plotly.graph_objs as go
|
8 |
-
from plotly.subplots import make_subplots
|
9 |
|
10 |
# Load the model
|
11 |
llm = load_model(openai_api_key)
|
12 |
|
13 |
-
def create_charts(results):
|
14 |
-
charts = {}
|
15 |
-
explanations = {}
|
16 |
-
general_impressions = {}
|
17 |
-
|
18 |
-
for speaker_id, data in results.items():
|
19 |
-
charts[speaker_id] = {}
|
20 |
-
explanations[speaker_id] = {}
|
21 |
-
|
22 |
-
# Extract general impression
|
23 |
-
general_impressions[speaker_id] = data.get('general_impression', "No general impression provided.")
|
24 |
-
|
25 |
-
# Attachment Styles
|
26 |
-
attachment_data = data['attachments']
|
27 |
-
labels = ['Secured', 'Anxious-Preoccupied', 'Dismissive-Avoidant', 'Fearful-Avoidant']
|
28 |
-
values = [getattr(attachment_data, 'secured', 0),
|
29 |
-
getattr(attachment_data, 'anxious_preoccupied', 0),
|
30 |
-
getattr(attachment_data, 'dismissive_avoidant', 0),
|
31 |
-
getattr(attachment_data, 'fearful_avoidant', 0)]
|
32 |
-
colors = ['blue', 'orange', 'green', 'red']
|
33 |
-
|
34 |
-
fig = go.Figure(data=[go.Bar(x=labels, y=values, marker_color=colors)])
|
35 |
-
fig.update_layout(title=f'{speaker_id}: Attachment Styles', yaxis_range=[0, 1])
|
36 |
-
charts[speaker_id]['attachment'] = fig
|
37 |
-
explanations[speaker_id]['attachment'] = attachment_data.explanation
|
38 |
-
|
39 |
-
# Big Five Traits
|
40 |
-
bigfive_data = data['bigfive']
|
41 |
-
labels = ['Extraversion', 'Agreeableness', 'Conscientiousness', 'Neuroticism', 'Openness']
|
42 |
-
values = [bigfive_data.extraversion, bigfive_data.agreeableness,
|
43 |
-
bigfive_data.conscientiousness, bigfive_data.neuroticism, bigfive_data.openness]
|
44 |
-
colors = ['blue', 'green', 'red', 'purple', 'orange']
|
45 |
-
|
46 |
-
fig = go.Figure(data=[go.Bar(x=labels, y=values, marker_color=colors)])
|
47 |
-
fig.update_layout(title=f'{speaker_id}: Big Five Traits', yaxis_range=[0, 10])
|
48 |
-
charts[speaker_id]['bigfive'] = fig
|
49 |
-
explanations[speaker_id]['bigfive'] = bigfive_data.explanation
|
50 |
-
|
51 |
-
# Personality Disorders
|
52 |
-
personality_data = data['personalities']
|
53 |
-
labels = ['Depressed', 'Paranoid', 'Schizoid-Schizotypal', 'Antisocial-Psychopathic',
|
54 |
-
'Borderline-Dysregulated', 'Narcissistic', 'Anxious-Avoidant', 'Dependent-Victimized', 'Obsessional']
|
55 |
-
values = [personality_data.depressed, personality_data.paranoid,
|
56 |
-
personality_data.schizoid_schizotypal, personality_data.antisocial_psychopathic,
|
57 |
-
personality_data.borderline_dysregulated, personality_data.narcissistic,
|
58 |
-
personality_data.anxious_avoidant, personality_data.dependent_victimized,
|
59 |
-
personality_data.obsessional]
|
60 |
-
colors = ['gray', 'purple', 'gold', 'black', 'red', 'orange', 'green', 'cyan', 'brown']
|
61 |
-
|
62 |
-
fig = go.Figure(data=[go.Bar(x=labels, y=values, marker_color=colors)])
|
63 |
-
fig.update_layout(title=f'{speaker_id}: Personality Disorders', yaxis_range=[0, 5])
|
64 |
-
charts[speaker_id]['personality'] = fig
|
65 |
-
explanations[speaker_id]['personality'] = personality_data.explanation
|
66 |
-
|
67 |
-
# Attachment Dimensions (Radar Chart)
|
68 |
-
dimensions_data = data['attachments']
|
69 |
-
labels = ['Self', 'Others', 'Anxiety', 'Avoidance']
|
70 |
-
values = [dimensions_data.self_model, dimensions_data.others_model,
|
71 |
-
dimensions_data.anxiety, dimensions_data.avoidance]
|
72 |
-
|
73 |
-
fig = go.Figure(data=go.Scatterpolar(
|
74 |
-
r=values,
|
75 |
-
theta=labels,
|
76 |
-
fill='toself'
|
77 |
-
))
|
78 |
-
fig.update_layout(
|
79 |
-
polar=dict(
|
80 |
-
radialaxis=dict(visible=True, range=[0, 10])
|
81 |
-
),
|
82 |
-
showlegend=False,
|
83 |
-
title=f'{speaker_id}: Attachment Dimensions'
|
84 |
-
)
|
85 |
-
charts[speaker_id]['dimensions'] = fig
|
86 |
-
|
87 |
-
return charts, explanations, general_impressions
|
88 |
-
|
89 |
def analyze_video(video_path, progress=gr.Progress()):
|
90 |
start_time = time.time()
|
91 |
if not video_path:
|
|
|
2 |
from llm_loader import load_model
|
3 |
from processing import process_input
|
4 |
from transcription_diarization import diarize_audio
|
5 |
+
from visualization import create_charts
|
6 |
import time
|
7 |
from config import openai_api_key
|
|
|
|
|
8 |
|
9 |
# Load the model
|
10 |
llm = load_model(openai_api_key)
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
def analyze_video(video_path, progress=gr.Progress()):
|
13 |
start_time = time.time()
|
14 |
if not video_path:
|