Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,40 +10,26 @@ from config import openai_api_key
|
|
| 10 |
llm = load_model(openai_api_key)
|
| 11 |
|
| 12 |
def analyze_video(video_path, max_speakers, progress=gr.Progress()):
|
| 13 |
-
|
| 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")
|
| 19 |
-
transcription = diarize_audio(video_path, max_speakers)
|
| 20 |
-
print("Transcription:", transcription) # Debug print
|
| 21 |
-
progress(0.5, desc="Transcription and diarization complete.")
|
| 22 |
-
|
| 23 |
-
progress(0.6, desc="Processing transcription")
|
| 24 |
-
results = process_input(transcription, llm)
|
| 25 |
-
progress(0.7, desc="Transcription processing complete.")
|
| 26 |
-
|
| 27 |
-
progress(0.9, desc="Generating charts")
|
| 28 |
-
charts, explanations = create_charts(results)
|
| 29 |
-
progress(1.0, desc="Charts generation complete.")
|
| 30 |
-
|
| 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 create_output_components():
|
| 42 |
with gr.Row() as row:
|
| 43 |
with gr.Column():
|
| 44 |
-
transcript = gr.Textbox(label="Transcript", lines=10)
|
|
|
|
| 45 |
tabs = gr.Tabs()
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
return row, transcript, tabs, execution_info
|
| 48 |
|
| 49 |
with gr.Blocks() as iface:
|
|
@@ -61,35 +47,41 @@ with gr.Blocks() as iface:
|
|
| 61 |
|
| 62 |
if "error" in results:
|
| 63 |
return {
|
| 64 |
-
transcript_output: "",
|
| 65 |
-
tabs_output: gr.
|
| 66 |
-
execution_info_output: results["error"]
|
| 67 |
}
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
speaker_explanations = results["explanations"][speaker_id]
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
gr.
|
| 75 |
-
gr.
|
| 76 |
-
gr.
|
| 77 |
-
gr.
|
| 78 |
-
gr.
|
| 79 |
-
gr.
|
| 80 |
-
gr.
|
| 81 |
-
|
|
|
|
|
|
|
| 82 |
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
|
| 89 |
analyze_button.click(
|
| 90 |
fn=run_analysis,
|
| 91 |
inputs=[video_input, max_speakers],
|
| 92 |
-
outputs=[transcript_output, tabs_output, execution_info_output],
|
| 93 |
show_progress=True
|
| 94 |
)
|
| 95 |
|
|
|
|
| 10 |
llm = load_model(openai_api_key)
|
| 11 |
|
| 12 |
def analyze_video(video_path, max_speakers, progress=gr.Progress()):
|
| 13 |
+
# ... (keep the existing analyze_video function as is)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
def create_output_components():
|
| 16 |
with gr.Row() as row:
|
| 17 |
with gr.Column():
|
| 18 |
+
transcript = gr.Textbox(label="Transcript", lines=10, visible=False)
|
| 19 |
+
|
| 20 |
tabs = gr.Tabs()
|
| 21 |
+
for i in range(3): # Pre-create 3 tabs (max number of speakers)
|
| 22 |
+
with gr.Tab(f"Speaker {i+1}", visible=False) as tab:
|
| 23 |
+
gr.Markdown(f"## Speaker {i+1}", visible=False)
|
| 24 |
+
gr.Plot(label="Attachment", visible=False)
|
| 25 |
+
gr.Textbox(label="Attachment Styles Explanation", visible=False)
|
| 26 |
+
gr.Plot(label="Dimensions", visible=False)
|
| 27 |
+
gr.Plot(label="Big Five", visible=False)
|
| 28 |
+
gr.Textbox(label="Big Five Traits Explanation", visible=False)
|
| 29 |
+
gr.Plot(label="Personality", visible=False)
|
| 30 |
+
gr.Textbox(label="Personality Disorders Explanation", visible=False)
|
| 31 |
+
|
| 32 |
+
execution_info = gr.Textbox(label="Execution Information", visible=False)
|
| 33 |
return row, transcript, tabs, execution_info
|
| 34 |
|
| 35 |
with gr.Blocks() as iface:
|
|
|
|
| 47 |
|
| 48 |
if "error" in results:
|
| 49 |
return {
|
| 50 |
+
transcript_output: gr.update(value="", visible=False),
|
| 51 |
+
tabs_output: gr.update(visible=False),
|
| 52 |
+
execution_info_output: gr.update(value=results["error"], visible=True)
|
| 53 |
}
|
| 54 |
|
| 55 |
+
updates = {
|
| 56 |
+
transcript_output: gr.update(value=results["transcript"], visible=True),
|
| 57 |
+
execution_info_output: gr.update(value=f"Completed in {results['execution_time']} seconds.", visible=True)
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
for i, (speaker_id, speaker_charts) in enumerate(results["charts"].items()):
|
| 61 |
speaker_explanations = results["explanations"][speaker_id]
|
| 62 |
+
tab_updates = {
|
| 63 |
+
f"Speaker {i+1}": gr.update(visible=True, label=speaker_id),
|
| 64 |
+
f"Speaker {i+1}/0": gr.update(value=f"## {speaker_id}", visible=True),
|
| 65 |
+
f"Speaker {i+1}/1": gr.update(value=speaker_charts.get("attachment", None), visible=True),
|
| 66 |
+
f"Speaker {i+1}/2": gr.update(value=speaker_explanations.get("attachment", ""), visible=True),
|
| 67 |
+
f"Speaker {i+1}/3": gr.update(value=speaker_charts.get("dimensions", None), visible=True),
|
| 68 |
+
f"Speaker {i+1}/4": gr.update(value=speaker_charts.get("bigfive", None), visible=True),
|
| 69 |
+
f"Speaker {i+1}/5": gr.update(value=speaker_explanations.get("bigfive", ""), visible=True),
|
| 70 |
+
f"Speaker {i+1}/6": gr.update(value=speaker_charts.get("personality", None), visible=True),
|
| 71 |
+
f"Speaker {i+1}/7": gr.update(value=speaker_explanations.get("personality", ""), visible=True),
|
| 72 |
+
}
|
| 73 |
+
updates.update(tab_updates)
|
| 74 |
|
| 75 |
+
# Hide unused tabs
|
| 76 |
+
for i in range(len(results["charts"]), 3):
|
| 77 |
+
updates[f"Speaker {i+1}"] = gr.update(visible=False)
|
| 78 |
+
|
| 79 |
+
return updates
|
| 80 |
|
| 81 |
analyze_button.click(
|
| 82 |
fn=run_analysis,
|
| 83 |
inputs=[video_input, max_speakers],
|
| 84 |
+
outputs=[transcript_output, tabs_output, execution_info_output] + [component for tab in tabs_output.children for component in tab.children],
|
| 85 |
show_progress=True
|
| 86 |
)
|
| 87 |
|