Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -15,20 +15,16 @@ def analyze_video(video_path, max_speakers, progress=gr.Progress()):
|
|
15 |
if not video_path:
|
16 |
return [gr.Markdown("Please upload a video file.")] + [gr.update(visible=False)] * 48 + ["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.")
|
@@ -36,13 +32,9 @@ def analyze_video(video_path, max_speakers, progress=gr.Progress()):
|
|
36 |
end_time = time.time()
|
37 |
execution_time = end_time - start_time
|
38 |
|
39 |
-
# Prepare outputs for each speaker
|
40 |
output_components = []
|
41 |
-
speaker_count = len(charts)
|
42 |
-
|
43 |
for speaker_id, speaker_charts in charts.items():
|
44 |
speaker_explanations = explanations[speaker_id]
|
45 |
-
|
46 |
speaker_section = [
|
47 |
gr.Markdown(f"### {speaker_id}", visible=True),
|
48 |
gr.Plot(value=speaker_charts.get("attachment", None), visible=True),
|
@@ -53,30 +45,16 @@ def analyze_video(video_path, max_speakers, progress=gr.Progress()):
|
|
53 |
gr.Plot(value=speaker_charts.get("personality", None), visible=True),
|
54 |
gr.Textbox(value=speaker_explanations.get("personality", ""), label="Personality Disorders Explanation", visible=True),
|
55 |
]
|
56 |
-
|
57 |
output_components.extend(speaker_section)
|
58 |
|
59 |
-
# Add empty placeholders for remaining outputs if fewer speakers than expected
|
60 |
while len(output_components) < 48:
|
61 |
-
output_components.extend([
|
62 |
-
gr.Markdown(visible=False),
|
63 |
-
gr.Plot(visible=False),
|
64 |
-
gr.Textbox(visible=False),
|
65 |
-
gr.Plot(visible=False),
|
66 |
-
gr.Plot(visible=False),
|
67 |
-
gr.Textbox(visible=False),
|
68 |
-
gr.Plot(visible=False),
|
69 |
-
gr.Textbox(visible=False),
|
70 |
-
])
|
71 |
|
72 |
-
# Add the execution time
|
73 |
output_components.append(gr.Textbox(value=f"Completed in {int(execution_time)} seconds.", label="Execution Information", visible=True))
|
|
|
74 |
|
75 |
-
|
76 |
-
return output_components + [transcription]
|
77 |
|
78 |
-
# Define the Gradio interface
|
79 |
-
# Define the Gradio interface
|
80 |
with gr.Blocks() as iface:
|
81 |
gr.Markdown("# AI Personality Detection")
|
82 |
gr.Markdown("Upload a video")
|
@@ -86,9 +64,8 @@ with gr.Blocks() as iface:
|
|
86 |
|
87 |
analyze_button = gr.Button("Analyze")
|
88 |
|
89 |
-
# Create placeholders for output components
|
90 |
output_components = []
|
91 |
-
for _ in range(3):
|
92 |
output_components.extend([
|
93 |
gr.Markdown(visible=False),
|
94 |
gr.Plot(visible=False),
|
@@ -100,13 +77,9 @@ with gr.Blocks() as iface:
|
|
100 |
gr.Textbox(label="Personality Disorders Explanation", visible=False),
|
101 |
])
|
102 |
|
103 |
-
# Add execution info box
|
104 |
execution_info_box = gr.Textbox(label="Execution Information", value="Waiting for analysis...", lines=2)
|
105 |
-
output_components.append(execution_info_box)
|
106 |
-
|
107 |
-
# Add transcript output
|
108 |
transcript_output = gr.Textbox(label="Transcript", lines=10, visible=True)
|
109 |
-
output_components.
|
110 |
|
111 |
analyze_button.click(
|
112 |
fn=analyze_video,
|
@@ -115,6 +88,5 @@ with gr.Blocks() as iface:
|
|
115 |
show_progress=True
|
116 |
)
|
117 |
|
118 |
-
# Launch the app
|
119 |
if __name__ == "__main__":
|
120 |
iface.launch()
|
|
|
15 |
if not video_path:
|
16 |
return [gr.Markdown("Please upload a video file.")] + [gr.update(visible=False)] * 48 + ["Analysis not started.", ""]
|
17 |
|
|
|
18 |
progress(0, desc="Starting analysis...")
|
19 |
|
|
|
20 |
progress(0.2, desc="Starting transcription and diarization")
|
21 |
transcription = diarize_audio(video_path, max_speakers)
|
22 |
progress(0.6, desc="Transcription and diarization complete.")
|
23 |
|
|
|
24 |
progress(0.7, desc="Processing transcription")
|
25 |
results = process_input(transcription, llm)
|
26 |
progress(0.8, desc="Transcription processing complete.")
|
27 |
|
|
|
28 |
progress(0.9, desc="Generating charts")
|
29 |
charts, explanations = create_charts(results)
|
30 |
progress(1.0, desc="Charts generation complete.")
|
|
|
32 |
end_time = time.time()
|
33 |
execution_time = end_time - start_time
|
34 |
|
|
|
35 |
output_components = []
|
|
|
|
|
36 |
for speaker_id, speaker_charts in charts.items():
|
37 |
speaker_explanations = explanations[speaker_id]
|
|
|
38 |
speaker_section = [
|
39 |
gr.Markdown(f"### {speaker_id}", visible=True),
|
40 |
gr.Plot(value=speaker_charts.get("attachment", None), visible=True),
|
|
|
45 |
gr.Plot(value=speaker_charts.get("personality", None), visible=True),
|
46 |
gr.Textbox(value=speaker_explanations.get("personality", ""), label="Personality Disorders Explanation", visible=True),
|
47 |
]
|
|
|
48 |
output_components.extend(speaker_section)
|
49 |
|
|
|
50 |
while len(output_components) < 48:
|
51 |
+
output_components.extend([gr.update(visible=False)] * 8)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
|
|
53 |
output_components.append(gr.Textbox(value=f"Completed in {int(execution_time)} seconds.", label="Execution Information", visible=True))
|
54 |
+
output_components.append(gr.Textbox(value=transcription, label="Transcript", lines=10, visible=True))
|
55 |
|
56 |
+
return output_components
|
|
|
57 |
|
|
|
|
|
58 |
with gr.Blocks() as iface:
|
59 |
gr.Markdown("# AI Personality Detection")
|
60 |
gr.Markdown("Upload a video")
|
|
|
64 |
|
65 |
analyze_button = gr.Button("Analyze")
|
66 |
|
|
|
67 |
output_components = []
|
68 |
+
for _ in range(3):
|
69 |
output_components.extend([
|
70 |
gr.Markdown(visible=False),
|
71 |
gr.Plot(visible=False),
|
|
|
77 |
gr.Textbox(label="Personality Disorders Explanation", visible=False),
|
78 |
])
|
79 |
|
|
|
80 |
execution_info_box = gr.Textbox(label="Execution Information", value="Waiting for analysis...", lines=2)
|
|
|
|
|
|
|
81 |
transcript_output = gr.Textbox(label="Transcript", lines=10, visible=True)
|
82 |
+
output_components.extend([execution_info_box, transcript_output])
|
83 |
|
84 |
analyze_button.click(
|
85 |
fn=analyze_video,
|
|
|
88 |
show_progress=True
|
89 |
)
|
90 |
|
|
|
91 |
if __name__ == "__main__":
|
92 |
iface.launch()
|