Update app.py
Browse files
app.py
CHANGED
@@ -8,56 +8,13 @@ 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 |
-
|
12 |
-
print("Starting video processing...")
|
13 |
-
results = process_video(video_input_path, anomaly_threshold_input, fps, progress=progress)
|
14 |
-
print("Video processing completed.")
|
15 |
-
|
16 |
-
if isinstance(results[0], str) and results[0].startswith("Error"):
|
17 |
-
print(f"Error occurred: {results[0]}")
|
18 |
-
return [results[0]] + [None] * 27
|
19 |
-
|
20 |
-
exec_time, results_summary, df, mse_embeddings, mse_posture, mse_voice, \
|
21 |
-
mse_plot_embeddings, mse_plot_posture, mse_plot_voice, \
|
22 |
-
mse_histogram_embeddings, mse_histogram_posture, mse_histogram_voice, \
|
23 |
-
mse_heatmap_embeddings, mse_heatmap_posture, mse_heatmap_voice, \
|
24 |
-
face_samples_frequent, \
|
25 |
-
anomaly_faces_embeddings, anomaly_frames_posture_images, \
|
26 |
-
aligned_faces_folder, frames_folder, \
|
27 |
-
heatmap_video_path, combined_mse_plot, correlation_heatmap = results
|
28 |
-
|
29 |
-
anomaly_faces_embeddings_pil = [Image.fromarray(face) for face in anomaly_faces_embeddings] if anomaly_faces_embeddings is not None else []
|
30 |
-
anomaly_frames_posture_pil = [Image.fromarray(frame) for frame in anomaly_frames_posture_images] if anomaly_frames_posture_images is not None else []
|
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 |
-
exec_time, results_summary,
|
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,
|
39 |
-
mse_heatmap_embeddings, mse_heatmap_posture, mse_heatmap_voice,
|
40 |
-
anomaly_faces_embeddings_pil, anomaly_frames_posture_pil,
|
41 |
-
face_samples_frequent,
|
42 |
-
aligned_faces_folder, frames_folder,
|
43 |
-
mse_embeddings, mse_posture, mse_voice,
|
44 |
-
heatmap_video_path, combined_mse_plot, correlation_heatmap
|
45 |
-
]
|
46 |
-
|
47 |
-
return output
|
48 |
-
|
49 |
-
except Exception as e:
|
50 |
-
error_message = f"An error occurred: {str(e)}"
|
51 |
-
print(error_message)
|
52 |
-
import traceback
|
53 |
-
traceback.print_exc()
|
54 |
-
return [error_message] + [None] * 27
|
55 |
|
56 |
def show_results(outputs):
|
57 |
-
return gr.
|
58 |
|
59 |
def hide_description_show_results():
|
60 |
-
return gr.
|
61 |
|
62 |
with gr.Blocks() as iface:
|
63 |
with gr.Row():
|
@@ -73,7 +30,7 @@ with gr.Blocks() as iface:
|
|
73 |
execution_time = gr.Number(label="Execution Time (seconds)")
|
74 |
|
75 |
with gr.Tabs() as all_tabs:
|
76 |
-
with gr.Tab("Description",
|
77 |
gr.Markdown("""
|
78 |
# Multimodal Behavioral Anomalies Detection
|
79 |
|
@@ -118,7 +75,7 @@ with gr.Blocks() as iface:
|
|
118 |
process_btn.click(
|
119 |
hide_description_show_results,
|
120 |
inputs=None,
|
121 |
-
outputs=
|
122 |
).then(
|
123 |
process_and_show_completion,
|
124 |
inputs=[video_input, anomaly_threshold, fps_slider],
|
@@ -137,7 +94,7 @@ with gr.Blocks() as iface:
|
|
137 |
).then(
|
138 |
show_results,
|
139 |
inputs=None,
|
140 |
-
outputs=[all_tabs, execution_time_group]
|
141 |
)
|
142 |
|
143 |
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 |
+
# ... (keep the existing function code)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
def show_results(outputs):
|
14 |
+
return [gr.Tab.update(visible=True) for _ in range(4)] + [gr.Tab.update(visible=False)], gr.Group(visible=True)
|
15 |
|
16 |
def hide_description_show_results():
|
17 |
+
return [gr.Tab.update(visible=False)] + [gr.Tab.update(visible=True) for _ in range(4)]
|
18 |
|
19 |
with gr.Blocks() as iface:
|
20 |
with gr.Row():
|
|
|
30 |
execution_time = gr.Number(label="Execution Time (seconds)")
|
31 |
|
32 |
with gr.Tabs() as all_tabs:
|
33 |
+
with gr.Tab("Description", visible=True):
|
34 |
gr.Markdown("""
|
35 |
# Multimodal Behavioral Anomalies Detection
|
36 |
|
|
|
75 |
process_btn.click(
|
76 |
hide_description_show_results,
|
77 |
inputs=None,
|
78 |
+
outputs=all_tabs.children
|
79 |
).then(
|
80 |
process_and_show_completion,
|
81 |
inputs=[video_input, anomaly_threshold, fps_slider],
|
|
|
94 |
).then(
|
95 |
show_results,
|
96 |
inputs=None,
|
97 |
+
outputs=[all_tabs.children, execution_time_group]
|
98 |
)
|
99 |
|
100 |
if __name__ == "__main__":
|