Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
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([
|
60 |
|
61 |
output_components.append(f"Completed in {int(execution_time)} seconds.") # execution info
|
62 |
|
63 |
return output_components
|
64 |
|
65 |
-
def
|
66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
87 |
-
|
88 |
# Add transcript output near the top
|
89 |
-
|
90 |
-
output_components.append(
|
91 |
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
with gr.
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
|
|
107 |
|
108 |
# Add execution info component
|
109 |
-
|
110 |
-
output_components.append(
|
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=
|
123 |
inputs=[video_input],
|
124 |
-
outputs=output_components
|
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(
|
|
|
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
|