Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
|
|
2 |
from llm_loader import load_model
|
3 |
from processing import process_input
|
4 |
from transcription_diarization import process_video
|
5 |
-
|
6 |
import os
|
7 |
import time
|
8 |
from config import hf_token, openai_api_key
|
@@ -21,79 +21,6 @@ LANGUAGE_MAP = {
|
|
21 |
"Arabic": "ar"
|
22 |
}
|
23 |
|
24 |
-
def create_charts(results):
|
25 |
-
charts = {}
|
26 |
-
explanations = {}
|
27 |
-
|
28 |
-
speaker_id = "Speaker 1" # Default speaker ID
|
29 |
-
speaker_charts = {}
|
30 |
-
speaker_explanations = {}
|
31 |
-
|
32 |
-
# Attachment Styles
|
33 |
-
attachment_data = results.get('attachments')
|
34 |
-
if attachment_data:
|
35 |
-
fig_attachment = go.Figure(go.Bar(
|
36 |
-
x=['Secured', 'Anxious-Preoccupied', 'Dismissive-Avoidant', 'Fearful-Avoidant'],
|
37 |
-
y=[getattr(attachment_data, 'secured', 0), getattr(attachment_data, 'anxious_preoccupied', 0),
|
38 |
-
getattr(attachment_data, 'dismissive_avoidant', 0), getattr(attachment_data, 'fearful_avoidant', 0)],
|
39 |
-
marker_color=['blue', 'orange', 'green', 'red']
|
40 |
-
))
|
41 |
-
fig_attachment.update_layout(title_text=f"Attachment Styles - {speaker_id}", showlegend=False)
|
42 |
-
speaker_charts["attachment"] = fig_attachment
|
43 |
-
speaker_explanations["attachment"] = getattr(attachment_data, 'explanation', '')
|
44 |
-
|
45 |
-
# Attachment Dimensions (Radar Chart)
|
46 |
-
fig_dimensions = go.Figure(go.Scatterpolar(
|
47 |
-
r=[getattr(attachment_data, 'avoidance', 0), getattr(attachment_data, 'anxiety', 0),
|
48 |
-
getattr(attachment_data, 'self_rating', 0), getattr(attachment_data, 'others_rating', 0)],
|
49 |
-
theta=['Avoidance', 'Anxiety', 'Self', 'Others'],
|
50 |
-
fill='toself'
|
51 |
-
))
|
52 |
-
fig_dimensions.update_layout(title_text=f"Attachment Dimensions - {speaker_id}", showlegend=False)
|
53 |
-
speaker_charts["dimensions"] = fig_dimensions
|
54 |
-
|
55 |
-
# Big Five Traits
|
56 |
-
bigfive_data = results.get('bigfive')
|
57 |
-
if bigfive_data:
|
58 |
-
fig_bigfive = go.Figure(go.Bar(
|
59 |
-
x=['Extraversion', 'Agreeableness', 'Conscientiousness', 'Neuroticism', 'Openness'],
|
60 |
-
y=[getattr(bigfive_data, 'extraversion', 0), getattr(bigfive_data, 'agreeableness', 0),
|
61 |
-
getattr(bigfive_data, 'conscientiousness', 0), getattr(bigfive_data, 'neuroticism', 0),
|
62 |
-
getattr(bigfive_data, 'openness', 0)],
|
63 |
-
marker_color=['blue', 'green', 'red', 'purple', 'orange']
|
64 |
-
))
|
65 |
-
fig_bigfive.update_layout(title_text=f"Big Five Traits - {speaker_id}", showlegend=False)
|
66 |
-
speaker_charts["bigfive"] = fig_bigfive
|
67 |
-
speaker_explanations["bigfive"] = getattr(bigfive_data, 'explanation', '')
|
68 |
-
|
69 |
-
# Personality Disorders
|
70 |
-
personality_data = results.get('personalities')
|
71 |
-
if personality_data:
|
72 |
-
fig_personality = go.Figure(go.Bar(
|
73 |
-
x=['Antisocial', 'Narcissistic', 'Depressed', 'Anxious-Avoidant',
|
74 |
-
'Obsessive', 'Paranoid', 'Borderline', 'Dependent', 'Schizoid-Schizotypal'],
|
75 |
-
y=[getattr(personality_data, 'antisocial_psychopathic', 0), getattr(personality_data, 'narcissistic', 0),
|
76 |
-
getattr(personality_data, 'depressed', 0), getattr(personality_data, 'anxious_avoidant', 0),
|
77 |
-
getattr(personality_data, 'obsessional', 0), getattr(personality_data, 'paranoid', 0),
|
78 |
-
getattr(personality_data, 'borderline_dysregulated', 0), getattr(personality_data, 'dependent_victimized', 0),
|
79 |
-
getattr(personality_data, 'schizoid_schizotypal', 0)],
|
80 |
-
marker_color=['black', 'orange', 'gray', 'green', 'brown', 'purple', 'red', 'cyan', 'magenta']
|
81 |
-
))
|
82 |
-
fig_personality.update_layout(title_text=f"Personality Disorders - {speaker_id}", showlegend=False)
|
83 |
-
speaker_charts["personality"] = fig_personality
|
84 |
-
speaker_explanations["personality"] = getattr(personality_data, 'explanation', '')
|
85 |
-
|
86 |
-
# Update all charts to take full width
|
87 |
-
for fig in speaker_charts.values():
|
88 |
-
fig.update_layout(height=400, width=None, margin=dict(l=50, r=50, t=100, b=50))
|
89 |
-
|
90 |
-
# Store the charts and explanations
|
91 |
-
charts[speaker_id] = speaker_charts
|
92 |
-
explanations[speaker_id] = speaker_explanations
|
93 |
-
|
94 |
-
return charts, explanations
|
95 |
-
|
96 |
-
|
97 |
def analyze_video(video_path, language_display_name, max_speakers, progress=gr.Progress()):
|
98 |
start_time = time.time()
|
99 |
|
@@ -132,11 +59,6 @@ def analyze_video(video_path, language_display_name, max_speakers, progress=gr.P
|
|
132 |
end_time = time.time()
|
133 |
execution_time = end_time - start_time
|
134 |
|
135 |
-
# Prepare outputs for each speaker
|
136 |
-
output_components = []
|
137 |
-
for speaker_id, speaker_charts in charts.items():
|
138 |
-
speaker_explanations = explanations[speaker_id]
|
139 |
-
|
140 |
# Prepare outputs for each speaker
|
141 |
output_components = []
|
142 |
for speaker_id, speaker_charts in charts.items():
|
|
|
2 |
from llm_loader import load_model
|
3 |
from processing import process_input
|
4 |
from transcription_diarization import process_video
|
5 |
+
from visualization import create_charts
|
6 |
import os
|
7 |
import time
|
8 |
from config import hf_token, openai_api_key
|
|
|
21 |
"Arabic": "ar"
|
22 |
}
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
def analyze_video(video_path, language_display_name, max_speakers, progress=gr.Progress()):
|
25 |
start_time = time.time()
|
26 |
|
|
|
59 |
end_time = time.time()
|
60 |
execution_time = end_time - start_time
|
61 |
|
|
|
|
|
|
|
|
|
|
|
62 |
# Prepare outputs for each speaker
|
63 |
output_components = []
|
64 |
for speaker_id, speaker_charts in charts.items():
|