reab5555 commited on
Commit
a655d29
·
verified ·
1 Parent(s): a3950aa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -33
app.py CHANGED
@@ -72,42 +72,47 @@ with gr.Blocks() as iface:
72
  results = analyze_video(video_path, max_speakers)
73
 
74
  if "error" in results:
75
- return {
76
- transcript_output: gr.update(value="", visible=False),
77
- tabs_output: gr.update(visible=False),
78
- execution_info_output: gr.update(value=results["error"], visible=True)
79
- }
80
-
81
- updates = {
82
- transcript_output: gr.update(value=results["transcript"], visible=True),
83
- execution_info_output: gr.update(value=f"Completed in {results['execution_time']} seconds.", visible=True)
84
- }
85
-
86
- for i, (speaker_id, speaker_charts) in enumerate(results["charts"].items()):
87
- speaker_explanations = results["explanations"][speaker_id]
88
- tab_updates = {
89
- f"Speaker {i+1}": gr.update(visible=True, label=speaker_id),
90
- f"Speaker {i+1}/0": gr.update(value=f"## {speaker_id}", visible=True),
91
- f"Speaker {i+1}/1": gr.update(value=speaker_charts.get("attachment", None), visible=True),
92
- f"Speaker {i+1}/2": gr.update(value=speaker_explanations.get("attachment", ""), visible=True),
93
- f"Speaker {i+1}/3": gr.update(value=speaker_charts.get("dimensions", None), visible=True),
94
- f"Speaker {i+1}/4": gr.update(value=speaker_charts.get("bigfive", None), visible=True),
95
- f"Speaker {i+1}/5": gr.update(value=speaker_explanations.get("bigfive", ""), visible=True),
96
- f"Speaker {i+1}/6": gr.update(value=speaker_charts.get("personality", None), visible=True),
97
- f"Speaker {i+1}/7": gr.update(value=speaker_explanations.get("personality", ""), visible=True),
98
- }
99
- updates.update(tab_updates)
100
-
101
- # Hide unused tabs
102
- for i in range(len(results["charts"]), 3):
103
- updates[f"Speaker {i+1}"] = gr.update(visible=False)
104
-
105
- return updates
106
-
 
107
  analyze_button.click(
108
  fn=run_analysis,
109
  inputs=[video_input, max_speakers],
110
- outputs=[transcript_output, tabs_output, execution_info_output] + [component for tab in tabs_output.children for component in tab.children],
 
 
 
 
111
  show_progress=True
112
  )
113
 
 
72
  results = analyze_video(video_path, max_speakers)
73
 
74
  if "error" in results:
75
+ return [
76
+ "", # transcript
77
+ gr.Tabs(), # tabs
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 [transcript, gr.Tabs.update(selected=0), execution_info] + 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