Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,7 +12,7 @@ llm = load_model(openai_api_key)
|
|
| 12 |
def analyze_video(video_path, max_speakers, progress=gr.Progress()):
|
| 13 |
start_time = time.time()
|
| 14 |
if not video_path:
|
| 15 |
-
return
|
| 16 |
|
| 17 |
progress(0, desc="Starting analysis...")
|
| 18 |
progress(0.2, desc="Starting transcription and diarization")
|
|
@@ -31,38 +31,44 @@ def analyze_video(video_path, max_speakers, progress=gr.Progress()):
|
|
| 31 |
end_time = time.time()
|
| 32 |
execution_time = end_time - start_time
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
speaker_id = list(charts.keys())[i]
|
| 43 |
-
speaker_charts = charts[speaker_id]
|
| 44 |
-
speaker_explanations = explanations[speaker_id]
|
| 45 |
-
output_components.extend([
|
| 46 |
-
gr.Markdown(f"## {speaker_id}", visible=True),
|
| 47 |
-
gr.Plot(value=speaker_charts.get("attachment", None), visible=True),
|
| 48 |
-
gr.Textbox(value=speaker_explanations.get("attachment", ""), label="Attachment Styles Explanation",
|
| 49 |
-
visible=True),
|
| 50 |
-
gr.Plot(value=speaker_charts.get("dimensions", None), visible=True),
|
| 51 |
-
gr.Plot(value=speaker_charts.get("bigfive", None), visible=True),
|
| 52 |
-
gr.Textbox(value=speaker_explanations.get("bigfive", ""), label="Big Five Traits Explanation",
|
| 53 |
-
visible=True),
|
| 54 |
-
gr.Plot(value=speaker_charts.get("personality", None), visible=True),
|
| 55 |
-
gr.Textbox(value=speaker_explanations.get("personality", ""), label="Personality Disorders Explanation",
|
| 56 |
-
visible=True),
|
| 57 |
-
])
|
| 58 |
-
else:
|
| 59 |
-
# Add placeholder components for unused speakers
|
| 60 |
-
output_components.extend([gr.update(visible=False)] * 8)
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
# Add execution info
|
| 63 |
output_components.append(
|
| 64 |
-
gr.Textbox(value=f"Completed in {
|
| 65 |
-
|
|
|
|
| 66 |
return output_components
|
| 67 |
|
| 68 |
with gr.Blocks() as iface:
|
|
@@ -73,31 +79,17 @@ with gr.Blocks() as iface:
|
|
| 73 |
max_speakers = gr.Slider(minimum=1, maximum=3, step=1, value=2, label="Maximum Number of Speakers")
|
| 74 |
analyze_button = gr.Button("Analyze")
|
| 75 |
|
| 76 |
-
|
| 77 |
-
output_components = [
|
| 78 |
-
gr.Textbox(label="Transcript", lines=10, visible=True)
|
| 79 |
-
]
|
| 80 |
-
|
| 81 |
-
# Create components for up to 3 speakers
|
| 82 |
-
for _ in range(3):
|
| 83 |
-
output_components.extend([
|
| 84 |
-
gr.Markdown(visible=False),
|
| 85 |
-
gr.Plot(visible=False),
|
| 86 |
-
gr.Textbox(label="Attachment Styles Explanation", visible=False),
|
| 87 |
-
gr.Plot(visible=False),
|
| 88 |
-
gr.Plot(visible=False),
|
| 89 |
-
gr.Textbox(label="Big Five Traits Explanation", visible=False),
|
| 90 |
-
gr.Plot(visible=False),
|
| 91 |
-
gr.Textbox(label="Personality Disorders Explanation", visible=False),
|
| 92 |
-
])
|
| 93 |
|
| 94 |
-
|
| 95 |
-
|
|
|
|
|
|
|
| 96 |
|
| 97 |
analyze_button.click(
|
| 98 |
-
fn=
|
| 99 |
inputs=[video_input, max_speakers],
|
| 100 |
-
outputs=
|
| 101 |
show_progress=True
|
| 102 |
)
|
| 103 |
|
|
|
|
| 12 |
def analyze_video(video_path, max_speakers, progress=gr.Progress()):
|
| 13 |
start_time = time.time()
|
| 14 |
if not video_path:
|
| 15 |
+
return {"error": "Please upload a video file."}
|
| 16 |
|
| 17 |
progress(0, desc="Starting analysis...")
|
| 18 |
progress(0.2, desc="Starting transcription and diarization")
|
|
|
|
| 31 |
end_time = time.time()
|
| 32 |
execution_time = end_time - start_time
|
| 33 |
|
| 34 |
+
return {
|
| 35 |
+
"transcript": transcription,
|
| 36 |
+
"charts": charts,
|
| 37 |
+
"explanations": explanations,
|
| 38 |
+
"execution_time": int(execution_time)
|
| 39 |
+
}
|
| 40 |
|
| 41 |
+
def generate_output_components(results):
|
| 42 |
+
if "error" in results:
|
| 43 |
+
return [gr.Markdown(results["error"])]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
+
output_components = []
|
| 46 |
+
|
| 47 |
+
# Add transcript
|
| 48 |
+
output_components.append(gr.Textbox(value=results["transcript"], label="Transcript", lines=10))
|
| 49 |
+
|
| 50 |
+
# Create tabs for each speaker
|
| 51 |
+
with gr.Tabs() as tabs:
|
| 52 |
+
for speaker_id, speaker_charts in results["charts"].items():
|
| 53 |
+
speaker_explanations = results["explanations"][speaker_id]
|
| 54 |
+
with gr.Tab(label=speaker_id):
|
| 55 |
+
speaker_section = [
|
| 56 |
+
gr.Markdown(f"## {speaker_id}\n<hr style='height:2px;border-width:0;color:black;background-color:black'>"),
|
| 57 |
+
gr.Plot(value=speaker_charts.get("attachment", None)),
|
| 58 |
+
gr.Textbox(value=speaker_explanations.get("attachment", ""), label="Attachment Styles Explanation"),
|
| 59 |
+
gr.Plot(value=speaker_charts.get("dimensions", None)),
|
| 60 |
+
gr.Plot(value=speaker_charts.get("bigfive", None)),
|
| 61 |
+
gr.Textbox(value=speaker_explanations.get("bigfive", ""), label="Big Five Traits Explanation"),
|
| 62 |
+
gr.Plot(value=speaker_charts.get("personality", None)),
|
| 63 |
+
gr.Textbox(value=speaker_explanations.get("personality", ""), label="Personality Disorders Explanation"),
|
| 64 |
+
]
|
| 65 |
+
output_components.extend(speaker_section)
|
| 66 |
+
|
| 67 |
# Add execution info
|
| 68 |
output_components.append(
|
| 69 |
+
gr.Textbox(value=f"Completed in {results['execution_time']} seconds.", label="Execution Information")
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
return output_components
|
| 73 |
|
| 74 |
with gr.Blocks() as iface:
|
|
|
|
| 79 |
max_speakers = gr.Slider(minimum=1, maximum=3, step=1, value=2, label="Maximum Number of Speakers")
|
| 80 |
analyze_button = gr.Button("Analyze")
|
| 81 |
|
| 82 |
+
output = gr.HTML()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
+
def run_analysis(video_path, max_speakers):
|
| 85 |
+
results = analyze_video(video_path, max_speakers)
|
| 86 |
+
output_components = generate_output_components(results)
|
| 87 |
+
return gr.HTML.update(value=gr.components.render(output_components))
|
| 88 |
|
| 89 |
analyze_button.click(
|
| 90 |
+
fn=run_analysis,
|
| 91 |
inputs=[video_input, max_speakers],
|
| 92 |
+
outputs=[output],
|
| 93 |
show_progress=True
|
| 94 |
)
|
| 95 |
|