reab5555 commited on
Commit
f6b2216
·
verified ·
1 Parent(s): 278800b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -55
app.py CHANGED
@@ -37,33 +37,51 @@ def analyze_video(video_path, progress=gr.Progress()):
37
  speaker_general_impression = general_impressions[speaker_id]
38
 
39
  speaker_section = [
40
- gr.Markdown(f"## {speaker_id}", visible=True),
41
- gr.Textbox(value=speaker_general_impression, label="General Impression",
42
- visible=True),
43
- gr.Plot(value=speaker_charts.get("attachment", None), visible=True),
44
- gr.Plot(value=speaker_charts.get("dimensions", None), visible=True),
45
-
46
- gr.Textbox(value=speaker_explanations.get("attachment", ""), label="Attachment Styles Explanation",
47
- visible=True),
48
- gr.Plot(value=speaker_charts.get("bigfive", None), visible=True),
49
- gr.Textbox(value=speaker_explanations.get("bigfive", ""), label="Big Five Traits Explanation",
50
- visible=True),
51
- gr.Plot(value=speaker_charts.get("personality", None), visible=True),
52
- gr.Textbox(value=speaker_explanations.get("personality", ""), label="Personality Disorders Explanation",
53
- visible=True),
54
  ]
55
  output_components.extend(speaker_section)
56
 
57
  # Pad with None for any missing speakers
58
  while len(output_components) < 28:
59
- output_components.extend([gr.update(visible=False)] * 9)
60
 
61
  output_components.append(f"Completed in {int(execution_time)} seconds.") # execution info
62
 
63
  return output_components
64
 
65
- def update_output(*args):
66
- return [gr.update(value=arg, visible=arg is not None) for arg in args]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
 
68
  def use_example():
69
  return "examples/Scenes.From.A.Marriage.US.mp4"
@@ -83,57 +101,45 @@ with gr.Blocks() as iface:
83
 
84
  # Create output components
85
  output_components = []
86
- tab_visibilities = []
87
-
88
  # Add transcript output near the top
89
- execution_info_box = gr.Textbox(label="Transcript", value="N/A", lines=1)
90
- output_components.append(execution_info_box)
91
 
92
- for i in range(3): # Assuming maximum of 3 speakers
93
- with gr.Tab(f"Speaker {i+1}", visible=False) as tab:
94
- tab_visibilities.append(tab)
95
- with gr.Row():
96
- output_components.extend([
97
- gr.Markdown(visible=False),
98
- gr.Textbox(label="General Impression", visible=False),
99
- gr.Plot(visible=False),
100
- gr.Plot(visible=False),
101
- gr.Textbox(label="Attachment Styles Explanation", visible=False),
102
- gr.Plot(visible=False),
103
- gr.Textbox(label="Big Five Traits Explanation", visible=False),
104
- gr.Plot(visible=False),
105
- gr.Textbox(label="Personality Disorders Explanation", visible=False),
106
- ])
 
107
 
108
  # Add execution info component
109
- transcript_output = gr.Textbox(label="Transcript", lines=10, visible=False)
110
- output_components.append(transcript_output)
111
-
112
- def update_interface(results):
113
- outputs = results[:-3] # All outputs except the last 3 (visible tabs info)
114
- visible_tabs = results[-3:] # Last 3 items are visible tabs info
115
-
116
- # Update tab visibility
117
- tab_updates = [gr.update(visible=(i in visible_tabs)) for i in range(1, 4)]
118
-
119
- return outputs + tab_updates
120
-
121
  analyze_button.click(
122
- fn=analyze_video,
123
  inputs=[video_input],
124
- outputs=output_components + tab_visibilities,
125
  show_progress=True
126
- ).then(
127
- fn=update_interface,
128
- inputs=output_components + tab_visibilities,
129
- outputs=output_components + tab_visibilities
130
  )
131
 
132
  use_example_button.click(
133
  fn=use_example,
134
  inputs=[],
135
  outputs=[video_input],
136
- ).then(fn=analyze_video,
 
137
  inputs=[video_input],
138
  outputs=output_components,
139
  show_progress=True
 
37
  speaker_general_impression = general_impressions[speaker_id]
38
 
39
  speaker_section = [
40
+ f"## {speaker_id}",
41
+ speaker_general_impression,
42
+ speaker_charts.get("attachment", None),
43
+ speaker_charts.get("dimensions", None),
44
+ speaker_explanations.get("attachment", ""),
45
+ speaker_charts.get("bigfive", None),
46
+ speaker_explanations.get("bigfive", ""),
47
+ speaker_charts.get("personality", None),
48
+ speaker_explanations.get("personality", ""),
 
 
 
 
 
49
  ]
50
  output_components.extend(speaker_section)
51
 
52
  # Pad with None for any missing speakers
53
  while len(output_components) < 28:
54
+ output_components.extend([None] * 9)
55
 
56
  output_components.append(f"Completed in {int(execution_time)} seconds.") # execution info
57
 
58
  return output_components
59
 
60
+ def analyze_and_update(video_path):
61
+ results = analyze_video(video_path)
62
+ outputs = results[:-1] # All outputs except the last one (execution info)
63
+ execution_info = results[-1] # Last item is execution info
64
+
65
+ visible_speakers = sum(1 for output in outputs[1:28:9] if output is not None)
66
+
67
+ # Update visibility of components
68
+ for i in range(len(outputs)):
69
+ if outputs[i] is None:
70
+ outputs[i] = gr.update(visible=False)
71
+ else:
72
+ outputs[i] = gr.update(value=outputs[i], visible=True)
73
+
74
+ # Update tab visibility
75
+ for i in range(3):
76
+ if i < visible_speakers:
77
+ outputs[i*9+1] = gr.update(value=f"## Speaker {i+1}", visible=True)
78
+ else:
79
+ for j in range(9):
80
+ outputs[i*9+j+1] = gr.update(visible=False)
81
+
82
+ outputs.append(gr.update(value=execution_info, visible=True))
83
+
84
+ return outputs
85
 
86
  def use_example():
87
  return "examples/Scenes.From.A.Marriage.US.mp4"
 
101
 
102
  # Create output components
103
  output_components = []
104
+
 
105
  # Add transcript output near the top
106
+ transcript_output = gr.Textbox(label="Transcript", lines=10, visible=False)
107
+ output_components.append(transcript_output)
108
 
109
+ tabs = gr.Tabs()
110
+ with tabs:
111
+ for i in range(3): # Assuming maximum of 3 speakers
112
+ with gr.Tab(f"Speaker {i+1}"):
113
+ with gr.Row():
114
+ output_components.extend([
115
+ gr.Markdown(visible=False),
116
+ gr.Textbox(label="General Impression", visible=False),
117
+ gr.Plot(visible=False),
118
+ gr.Plot(visible=False),
119
+ gr.Textbox(label="Attachment Styles Explanation", visible=False),
120
+ gr.Plot(visible=False),
121
+ gr.Textbox(label="Big Five Traits Explanation", visible=False),
122
+ gr.Plot(visible=False),
123
+ gr.Textbox(label="Personality Disorders Explanation", visible=False),
124
+ ])
125
 
126
  # Add execution info component
127
+ execution_info_box = gr.Textbox(label="Execution Info", value="N/A", lines=1)
128
+ output_components.append(execution_info_box)
129
+
 
 
 
 
 
 
 
 
 
130
  analyze_button.click(
131
+ fn=analyze_and_update,
132
  inputs=[video_input],
133
+ outputs=output_components,
134
  show_progress=True
 
 
 
 
135
  )
136
 
137
  use_example_button.click(
138
  fn=use_example,
139
  inputs=[],
140
  outputs=[video_input],
141
+ ).then(
142
+ fn=analyze_and_update,
143
  inputs=[video_input],
144
  outputs=output_components,
145
  show_progress=True