reab5555 commited on
Commit
cb2b50c
·
verified ·
1 Parent(s): 8f89005

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -54
app.py CHANGED
@@ -44,19 +44,54 @@ def create_output_components():
44
  transcript = gr.Textbox(label="Transcript", lines=10, visible=False)
45
 
46
  tabs = gr.Tabs()
 
47
  for i in range(3): # Pre-create 3 tabs (max number of speakers)
48
  with gr.Tab(f"Speaker {i+1}", visible=False) as tab:
49
- gr.Markdown(f"## Speaker {i+1}", visible=False)
50
- gr.Plot(label="Attachment", visible=False)
51
- gr.Textbox(label="Attachment Styles Explanation", visible=False)
52
- gr.Plot(label="Dimensions", visible=False)
53
- gr.Plot(label="Big Five", visible=False)
54
- gr.Textbox(label="Big Five Traits Explanation", visible=False)
55
- gr.Plot(label="Personality", visible=False)
56
- gr.Textbox(label="Personality Disorders Explanation", visible=False)
 
 
 
57
 
58
- execution_info = gr.Textbox(label="Execution Information", visible=True)
59
- return row, transcript, tabs, execution_info
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
 
61
  with gr.Blocks() as iface:
62
  gr.Markdown("# AI Personality Detection")
@@ -66,54 +101,14 @@ with gr.Blocks() as iface:
66
  max_speakers = gr.Slider(minimum=1, maximum=3, step=1, value=2, label="Maximum Number of Speakers")
67
  analyze_button = gr.Button("Analyze")
68
 
69
- output_row, transcript_output, tabs_output, execution_info_output = create_output_components()
70
-
71
- def run_analysis(video_path, max_speakers):
72
- results = analyze_video(video_path, max_speakers)
73
-
74
- if "error" in results:
75
- return [
76
- "", # transcript
77
- None, # tabs (no update)
78
- results["error"], # execution_info
79
- ] + [gr.update(visible=False)] * 24 # 8 components per tab * 3 tabs
80
-
81
- transcript = results["transcript"]
82
- execution_info = f"Completed in {results['execution_time']} seconds."
83
-
84
- tab_updates = []
85
- for i in range(3): # For each potential speaker
86
- if i < len(results["charts"]):
87
- speaker_id = list(results["charts"].keys())[i]
88
- speaker_charts = results["charts"][speaker_id]
89
- speaker_explanations = results["explanations"][speaker_id]
90
-
91
- tab_updates.extend([
92
- gr.update(visible=True, label=speaker_id), # Tab visibility and label
93
- gr.update(value=f"## {speaker_id}", visible=True), # Markdown
94
- gr.update(value=speaker_charts.get("attachment", None), visible=True), # Attachment plot
95
- gr.update(value=speaker_explanations.get("attachment", ""), visible=True), # Attachment explanation
96
- gr.update(value=speaker_charts.get("dimensions", None), visible=True), # Dimensions plot
97
- gr.update(value=speaker_charts.get("bigfive", None), visible=True), # Big Five plot
98
- gr.update(value=speaker_explanations.get("bigfive", ""), visible=True), # Big Five explanation
99
- gr.update(value=speaker_charts.get("personality", None), visible=True), # Personality plot
100
- gr.update(value=speaker_explanations.get("personality", ""), visible=True), # Personality explanation
101
- ])
102
- else:
103
- tab_updates.extend([gr.update(visible=False)] * 9) # Hide unused tab and its components
104
-
105
- return [gr.update(value=transcript, visible=True), None, gr.update(value=execution_info, visible=True)] + tab_updates
106
-
107
- # Modify the analyze_button.click setup
108
  analyze_button.click(
109
  fn=run_analysis,
110
  inputs=[video_input, max_speakers],
111
- outputs=[
112
- transcript_output,
113
- tabs_output,
114
- execution_info_output
115
- ] + [component for tab in tabs_output.children for component in tab.children],
116
  show_progress=True
117
  )
 
118
  if __name__ == "__main__":
119
  iface.launch()
 
44
  transcript = gr.Textbox(label="Transcript", lines=10, visible=False)
45
 
46
  tabs = gr.Tabs()
47
+ tab_components = []
48
  for i in range(3): # Pre-create 3 tabs (max number of speakers)
49
  with gr.Tab(f"Speaker {i+1}", visible=False) as tab:
50
+ speaker_components = [
51
+ gr.Markdown(f"## Speaker {i+1}", visible=False),
52
+ gr.Plot(label="Attachment", visible=False),
53
+ gr.Textbox(label="Attachment Styles Explanation", visible=False),
54
+ gr.Plot(label="Dimensions", visible=False),
55
+ gr.Plot(label="Big Five", visible=False),
56
+ gr.Textbox(label="Big Five Traits Explanation", visible=False),
57
+ gr.Plot(label="Personality", visible=False),
58
+ gr.Textbox(label="Personality Disorders Explanation", visible=False)
59
+ ]
60
+ tab_components.extend(speaker_components)
61
 
62
+ execution_info = gr.Textbox(label="Execution Information", visible=False)
63
+ return row, transcript, tab_components, execution_info
64
+
65
+ def run_analysis(video_path, max_speakers):
66
+ results = analyze_video(video_path, max_speakers)
67
+
68
+ if "error" in results:
69
+ return [gr.update(value="", visible=False)] + [gr.update(visible=False)] * 24 + [gr.update(value=results["error"], visible=True)]
70
+
71
+ transcript = results["transcript"]
72
+ execution_info = f"Completed in {results['execution_time']} seconds."
73
+
74
+ tab_updates = []
75
+ for i in range(3): # For each potential speaker
76
+ if i < len(results["charts"]):
77
+ speaker_id = list(results["charts"].keys())[i]
78
+ speaker_charts = results["charts"][speaker_id]
79
+ speaker_explanations = results["explanations"][speaker_id]
80
+
81
+ tab_updates.extend([
82
+ gr.update(value=f"## {speaker_id}", visible=True), # Markdown
83
+ gr.update(value=speaker_charts.get("attachment", None), visible=True), # Attachment plot
84
+ gr.update(value=speaker_explanations.get("attachment", ""), visible=True), # Attachment explanation
85
+ gr.update(value=speaker_charts.get("dimensions", None), visible=True), # Dimensions plot
86
+ gr.update(value=speaker_charts.get("bigfive", None), visible=True), # Big Five plot
87
+ gr.update(value=speaker_explanations.get("bigfive", ""), visible=True), # Big Five explanation
88
+ gr.update(value=speaker_charts.get("personality", None), visible=True), # Personality plot
89
+ gr.update(value=speaker_explanations.get("personality", ""), visible=True), # Personality explanation
90
+ ])
91
+ else:
92
+ tab_updates.extend([gr.update(visible=False)] * 8) # Hide unused tab components
93
+
94
+ return [gr.update(value=transcript, visible=True)] + tab_updates + [gr.update(value=execution_info, visible=True)]
95
 
96
  with gr.Blocks() as iface:
97
  gr.Markdown("# AI Personality Detection")
 
101
  max_speakers = gr.Slider(minimum=1, maximum=3, step=1, value=2, label="Maximum Number of Speakers")
102
  analyze_button = gr.Button("Analyze")
103
 
104
+ output_row, transcript_output, tab_components, execution_info_output = create_output_components()
105
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  analyze_button.click(
107
  fn=run_analysis,
108
  inputs=[video_input, max_speakers],
109
+ outputs=[transcript_output] + tab_components + [execution_info_output],
 
 
 
 
110
  show_progress=True
111
  )
112
+
113
  if __name__ == "__main__":
114
  iface.launch()