Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
with gr.Blocks() as iface:
|
| 2 |
gr.Markdown("""
|
| 3 |
# Multimodal Behavioral Anomalies Detection
|
|
@@ -50,9 +108,6 @@ with gr.Blocks() as iface:
|
|
| 50 |
mse_heatmap_posture_store = gr.State()
|
| 51 |
mse_heatmap_voice_store = gr.State()
|
| 52 |
|
| 53 |
-
def show_results(outputs):
|
| 54 |
-
return gr.Group(visible=True)
|
| 55 |
-
|
| 56 |
process_btn.click(
|
| 57 |
process_and_show_completion,
|
| 58 |
inputs=[video_input, anomaly_threshold, fps_slider],
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import time
|
| 3 |
+
from video_processing import process_video
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import matplotlib
|
| 6 |
+
|
| 7 |
+
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)
|
| 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] * 23
|
| 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 = 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
|
| 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] * 23
|
| 55 |
+
|
| 56 |
+
def show_results(outputs):
|
| 57 |
+
return gr.Group(visible=True)
|
| 58 |
+
|
| 59 |
with gr.Blocks() as iface:
|
| 60 |
gr.Markdown("""
|
| 61 |
# Multimodal Behavioral Anomalies Detection
|
|
|
|
| 108 |
mse_heatmap_posture_store = gr.State()
|
| 109 |
mse_heatmap_voice_store = gr.State()
|
| 110 |
|
|
|
|
|
|
|
|
|
|
| 111 |
process_btn.click(
|
| 112 |
process_and_show_completion,
|
| 113 |
inputs=[video_input, anomaly_threshold, fps_slider],
|