reab5555 commited on
Commit
ae931c0
·
verified ·
1 Parent(s): 088a9a4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -50
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 [gr.Markdown("Please upload a video file.")] + [gr.update(visible=False)] * 25
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
- output_components = []
35
-
36
- # Add transcript
37
- output_components.append(gr.Textbox(value=transcription, label="Transcript", lines=10))
 
 
38
 
39
- # Create components for up to 3 speakers
40
- for i in range(3):
41
- if i < len(charts):
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 {int(execution_time)} seconds.", label="Execution Information"))
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
- # Create output components
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
- # Add execution info component
95
- output_components.append(gr.Textbox(label="Execution Information", visible=False))
 
 
96
 
97
  analyze_button.click(
98
- fn=analyze_video,
99
  inputs=[video_input, max_speakers],
100
- outputs=output_components,
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