Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
# Define the Gradio interface
|
2 |
with gr.Blocks() as iface:
|
3 |
gr.Markdown("# AI Personality Detection")
|
@@ -12,27 +83,41 @@ with gr.Blocks() as iface:
|
|
12 |
execution_info_box = gr.Textbox(label="Execution Information", value="Waiting for analysis...", lines=1)
|
13 |
|
14 |
# Create placeholders for output components
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
with gr.Tab(f"Speaker {i}"):
|
19 |
with gr.TabItem("Attachment Styles"):
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
analyze_button.click(
|
38 |
fn=analyze_video,
|
@@ -43,4 +128,4 @@ with gr.Blocks() as iface:
|
|
43 |
|
44 |
# Launch the app
|
45 |
if __name__ == "__main__":
|
46 |
-
iface.launch()
|
|
|
1 |
+
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 |
+
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, max_speakers, progress=gr.Progress()):
|
13 |
+
start_time = time.time()
|
14 |
+
|
15 |
+
if not video_path:
|
16 |
+
return [gr.Markdown("Please upload a video file.")] + [gr.update(visible=False)] * (max_speakers * 7 + max_speakers) + ["Analysis not started."]
|
17 |
+
|
18 |
+
# Start the progress bar
|
19 |
+
progress(0, desc="Starting analysis...")
|
20 |
+
|
21 |
+
# Progress for transcription and diarization
|
22 |
+
progress(0.2, desc="Starting transcription and diarization...")
|
23 |
+
transcription = diarize_audio(video_path, max_speakers)
|
24 |
+
progress(0.6, desc="Transcription and diarization complete.")
|
25 |
+
|
26 |
+
# Progress for processing the transcription
|
27 |
+
progress(0.7, desc="Processing transcription...")
|
28 |
+
results = process_input(transcription, llm)
|
29 |
+
progress(0.8, desc="Transcription processing complete.")
|
30 |
+
|
31 |
+
# Progress for creating charts
|
32 |
+
progress(0.9, desc="Generating charts...")
|
33 |
+
charts, explanations = create_charts(results)
|
34 |
+
progress(1.0, desc="Charts generation complete.")
|
35 |
+
|
36 |
+
end_time = time.time()
|
37 |
+
execution_time = end_time - start_time
|
38 |
+
|
39 |
+
# Prepare outputs for each speaker
|
40 |
+
output_components = []
|
41 |
+
|
42 |
+
for speaker_id in range(max_speakers):
|
43 |
+
speaker_charts = charts.get(speaker_id, {})
|
44 |
+
speaker_explanations = explanations.get(speaker_id, {})
|
45 |
+
|
46 |
+
# Check and assign plot outputs
|
47 |
+
attachment_plot = speaker_charts.get("attachment", None)
|
48 |
+
dimensions_plot = speaker_charts.get("dimensions", None)
|
49 |
+
bigfive_plot = speaker_charts.get("bigfive", None)
|
50 |
+
personality_plot = speaker_charts.get("personality", None)
|
51 |
+
|
52 |
+
speaker_section = [
|
53 |
+
gr.Plot(value=attachment_plot if attachment_plot else None, visible=True),
|
54 |
+
gr.Textbox(value=speaker_explanations.get("attachment", ""), label="Attachment Styles Explanation", visible=True),
|
55 |
+
gr.Plot(value=dimensions_plot if dimensions_plot else None, visible=True),
|
56 |
+
gr.Plot(value=bigfive_plot if bigfive_plot else None, visible=True),
|
57 |
+
gr.Textbox(value=speaker_explanations.get("bigfive", ""), label="Big Five Traits Explanation", visible=True),
|
58 |
+
gr.Plot(value=personality_plot if personality_plot else None, visible=True),
|
59 |
+
gr.Textbox(value=speaker_explanations.get("personality", ""), label="Personality Disorders Explanation", visible=True),
|
60 |
+
]
|
61 |
+
|
62 |
+
output_components.extend(speaker_section)
|
63 |
+
|
64 |
+
# Add the transcript at the end
|
65 |
+
output_components.append(gr.Textbox(value=transcription, label="Transcript", lines=10, visible=True))
|
66 |
+
|
67 |
+
# Add the execution time
|
68 |
+
output_components.append(gr.Textbox(value=f"Completed in {int(execution_time)} seconds.", label="Execution Information", visible=True))
|
69 |
+
|
70 |
+
return [gr.update(visible=True)] * (max_speakers * 7 + max_speakers) + output_components[-2:] # Making tabs and contents visible after analysis
|
71 |
+
|
72 |
# Define the Gradio interface
|
73 |
with gr.Blocks() as iface:
|
74 |
gr.Markdown("# AI Personality Detection")
|
|
|
83 |
execution_info_box = gr.Textbox(label="Execution Information", value="Waiting for analysis...", lines=1)
|
84 |
|
85 |
# Create placeholders for output components
|
86 |
+
def create_output_components(num_speakers):
|
87 |
+
output_components = []
|
88 |
+
for i in range(4):
|
|
|
89 |
with gr.TabItem("Attachment Styles"):
|
90 |
+
output_components.extend([
|
91 |
+
gr.Plot(visible=False),
|
92 |
+
gr.Textbox(label="Attachment Styles Explanation", visible=False)])
|
93 |
+
|
94 |
+
with gr.TabItem("Big Five Traits"):
|
95 |
+
output_components.extend([
|
96 |
+
gr.Plot(visible=False),
|
97 |
+
gr.Textbox(label="Big Five Traits Explanation", visible=False)])
|
98 |
+
|
99 |
+
with gr.TabItem("Personalities"):
|
100 |
+
output_components.extend([
|
101 |
+
gr.Plot(visible=False),
|
102 |
+
gr.Textbox(label="Personality Disorders Explanation", visible=False)])
|
103 |
+
|
104 |
+
output_components.append(gr.Textbox(label="Transcript", lines=10, visible=False))
|
105 |
+
output_components.append(gr.Textbox(label="Execution Information", visible=True))
|
106 |
+
|
107 |
+
return output_components
|
108 |
+
|
109 |
+
# Initialize with default number of speakers
|
110 |
+
output_components = create_output_components(2)
|
111 |
+
|
112 |
+
# Update the output components when the slider changes
|
113 |
+
def update_interface(max_speakers):
|
114 |
+
return create_output_components(max_speakers)
|
115 |
+
|
116 |
+
max_speakers.change(
|
117 |
+
fn=update_interface,
|
118 |
+
inputs=max_speakers,
|
119 |
+
outputs=output_components
|
120 |
+
)
|
121 |
|
122 |
analyze_button.click(
|
123 |
fn=analyze_video,
|
|
|
128 |
|
129 |
# Launch the app
|
130 |
if __name__ == "__main__":
|
131 |
+
iface.launch()
|