Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,8 @@ matplotlib.rcParams['figure.dpi'] = 300
|
|
8 |
matplotlib.rcParams['savefig.dpi'] = 300
|
9 |
|
10 |
def process_and_show_completion(video_input_path, anomaly_threshold_input, fps, progress=gr.Progress()):
|
|
|
|
|
11 |
try:
|
12 |
print("Starting video processing...")
|
13 |
results = process_video(video_input_path, anomaly_threshold_input, fps, progress=progress)
|
@@ -31,8 +33,11 @@ def process_and_show_completion(video_input_path, anomaly_threshold_input, fps,
|
|
31 |
|
32 |
face_samples_frequent = [Image.open(path) for path in face_samples_frequent] if face_samples_frequent is not None else []
|
33 |
|
|
|
|
|
|
|
34 |
output = [
|
35 |
-
|
36 |
df, mse_embeddings, mse_posture, mse_voice,
|
37 |
mse_plot_embeddings, mse_plot_posture, mse_plot_voice,
|
38 |
mse_histogram_embeddings, mse_histogram_posture, mse_histogram_voice,
|
@@ -54,10 +59,16 @@ def process_and_show_completion(video_input_path, anomaly_threshold_input, fps,
|
|
54 |
return [error_message] + [None] * 27
|
55 |
|
56 |
def show_results():
|
57 |
-
return [gr.Tab.update(visible=True) for _ in range(4)] + [gr.Tab.update(visible=False)]
|
58 |
|
59 |
def hide_description_show_results():
|
60 |
-
return [gr.Tab.update(visible=False)] + [gr.Tab.update(visible=True) for _ in range(4)]
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
with gr.Blocks() as iface:
|
63 |
with gr.Row():
|
@@ -70,7 +81,8 @@ with gr.Blocks() as iface:
|
|
70 |
|
71 |
execution_time_group = gr.Group(visible=False)
|
72 |
with execution_time_group:
|
73 |
-
execution_time = gr.Number(label="Execution Time
|
|
|
74 |
|
75 |
with gr.Tabs() as all_tabs:
|
76 |
description_tab = gr.Tab("Description")
|
@@ -121,9 +133,13 @@ with gr.Blocks() as iface:
|
|
121 |
mse_heatmap_voice_store = gr.State()
|
122 |
|
123 |
process_btn.click(
|
|
|
|
|
|
|
|
|
124 |
hide_description_show_results,
|
125 |
inputs=None,
|
126 |
-
outputs=[description_tab, facial_features_tab, body_posture_tab, voice_tab, combined_tab]
|
127 |
).then(
|
128 |
process_and_show_completion,
|
129 |
inputs=[video_input, anomaly_threshold, fps_slider],
|
@@ -142,7 +158,14 @@ with gr.Blocks() as iface:
|
|
142 |
).then(
|
143 |
show_results,
|
144 |
inputs=None,
|
145 |
-
outputs=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
)
|
147 |
|
148 |
if __name__ == "__main__":
|
|
|
8 |
matplotlib.rcParams['savefig.dpi'] = 300
|
9 |
|
10 |
def process_and_show_completion(video_input_path, anomaly_threshold_input, fps, progress=gr.Progress()):
|
11 |
+
start_time = time.time()
|
12 |
+
|
13 |
try:
|
14 |
print("Starting video processing...")
|
15 |
results = process_video(video_input_path, anomaly_threshold_input, fps, progress=progress)
|
|
|
33 |
|
34 |
face_samples_frequent = [Image.open(path) for path in face_samples_frequent] if face_samples_frequent is not None else []
|
35 |
|
36 |
+
end_time = time.time()
|
37 |
+
total_exec_time = end_time - start_time
|
38 |
+
|
39 |
output = [
|
40 |
+
total_exec_time, results_summary,
|
41 |
df, mse_embeddings, mse_posture, mse_voice,
|
42 |
mse_plot_embeddings, mse_plot_posture, mse_plot_voice,
|
43 |
mse_histogram_embeddings, mse_histogram_posture, mse_histogram_voice,
|
|
|
59 |
return [error_message] + [None] * 27
|
60 |
|
61 |
def show_results():
|
62 |
+
return [gr.Tab.update(visible=True) for _ in range(4)] + [gr.Tab.update(visible=False)]
|
63 |
|
64 |
def hide_description_show_results():
|
65 |
+
return [gr.Tab.update(visible=False)] + [gr.Tab.update(visible=True) for _ in range(4)], gr.Group.update(visible=True)
|
66 |
+
|
67 |
+
def start_execution_timer():
|
68 |
+
return gr.Number.update(value=0, visible=True), gr.Markdown.update(visible=True)
|
69 |
+
|
70 |
+
def update_execution_time():
|
71 |
+
return gr.Number.update()
|
72 |
|
73 |
with gr.Blocks() as iface:
|
74 |
with gr.Row():
|
|
|
81 |
|
82 |
execution_time_group = gr.Group(visible=False)
|
83 |
with execution_time_group:
|
84 |
+
execution_time = gr.Number(label="Execution Time", visible=False)
|
85 |
+
execution_time_text = gr.Markdown("Execution time will be displayed here", visible=False)
|
86 |
|
87 |
with gr.Tabs() as all_tabs:
|
88 |
description_tab = gr.Tab("Description")
|
|
|
133 |
mse_heatmap_voice_store = gr.State()
|
134 |
|
135 |
process_btn.click(
|
136 |
+
start_execution_timer,
|
137 |
+
inputs=None,
|
138 |
+
outputs=[execution_time, execution_time_text]
|
139 |
+
).then(
|
140 |
hide_description_show_results,
|
141 |
inputs=None,
|
142 |
+
outputs=[description_tab, facial_features_tab, body_posture_tab, voice_tab, combined_tab, execution_time_group]
|
143 |
).then(
|
144 |
process_and_show_completion,
|
145 |
inputs=[video_input, anomaly_threshold, fps_slider],
|
|
|
158 |
).then(
|
159 |
show_results,
|
160 |
inputs=None,
|
161 |
+
outputs=all_tabs.children
|
162 |
+
)
|
163 |
+
|
164 |
+
execution_time.change(
|
165 |
+
update_execution_time,
|
166 |
+
inputs=None,
|
167 |
+
outputs=execution_time_text,
|
168 |
+
every=1
|
169 |
)
|
170 |
|
171 |
if __name__ == "__main__":
|