Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,6 @@ import time
|
|
| 3 |
from video_processing import process_video
|
| 4 |
from PIL import Image
|
| 5 |
import matplotlib
|
| 6 |
-
import cv2
|
| 7 |
matplotlib.rcParams['figure.dpi'] = 500
|
| 8 |
matplotlib.rcParams['savefig.dpi'] = 500
|
| 9 |
|
|
@@ -15,7 +14,7 @@ def process_and_show_completion(video_input_path, anomaly_threshold_input, fps,
|
|
| 15 |
|
| 16 |
if isinstance(results[0], str) and results[0].startswith("Error"):
|
| 17 |
print(f"Error occurred: {results[0]}")
|
| 18 |
-
return [results[0]] + [None] *
|
| 19 |
|
| 20 |
exec_time, results_summary, df, mse_embeddings, mse_posture, \
|
| 21 |
mse_plot_embeddings, mse_histogram_embeddings, \
|
|
@@ -23,7 +22,7 @@ def process_and_show_completion(video_input_path, anomaly_threshold_input, fps,
|
|
| 23 |
mse_heatmap_embeddings, mse_heatmap_posture, \
|
| 24 |
face_samples_frequent, face_samples_other, \
|
| 25 |
anomaly_faces_embeddings, anomaly_frames_posture_images, \
|
| 26 |
-
aligned_faces_folder, frames_folder
|
| 27 |
|
| 28 |
anomaly_faces_embeddings_pil = [Image.fromarray(face) for face in anomaly_faces_embeddings]
|
| 29 |
anomaly_frames_posture_pil = [Image.fromarray(frame) for frame in anomaly_frames_posture_images]
|
|
@@ -40,7 +39,7 @@ def process_and_show_completion(video_input_path, anomaly_threshold_input, fps,
|
|
| 40 |
anomaly_faces_embeddings_pil, anomaly_frames_posture_pil,
|
| 41 |
face_samples_frequent, face_samples_other,
|
| 42 |
aligned_faces_folder, frames_folder,
|
| 43 |
-
mse_embeddings, mse_posture,
|
| 44 |
]
|
| 45 |
|
| 46 |
return output
|
|
@@ -50,14 +49,17 @@ def process_and_show_completion(video_input_path, anomaly_threshold_input, fps,
|
|
| 50 |
print(error_message)
|
| 51 |
import traceback
|
| 52 |
traceback.print_exc()
|
| 53 |
-
return [error_message] + [None] *
|
| 54 |
|
| 55 |
with gr.Blocks() as iface:
|
| 56 |
gr.Markdown("""
|
| 57 |
-
#
|
| 58 |
|
| 59 |
-
|
| 60 |
-
It
|
|
|
|
|
|
|
|
|
|
| 61 |
""")
|
| 62 |
|
| 63 |
with gr.Row():
|
|
@@ -84,9 +86,6 @@ with gr.Blocks() as iface:
|
|
| 84 |
mse_posture_heatmap = gr.Plot(label="MSE Heatmap: Body Posture")
|
| 85 |
anomaly_frames_posture = gr.Gallery(label="Anomaly Frames (Body Posture)", columns=6, rows=2, height="auto")
|
| 86 |
|
| 87 |
-
with gr.Tab("Annotated Video"):
|
| 88 |
-
annotated_video_output = gr.Video(label="Annotated Video")
|
| 89 |
-
|
| 90 |
with gr.Tab("Face Samples"):
|
| 91 |
face_samples_most_frequent = gr.Gallery(label="Most Frequent Person Samples (Target)", columns=6, rows=2, height="auto")
|
| 92 |
face_samples_others = gr.Gallery(label="Other Persons Samples", columns=6, rows=1, height="auto")
|
|
@@ -111,8 +110,7 @@ with gr.Blocks() as iface:
|
|
| 111 |
anomaly_frames_features, anomaly_frames_posture,
|
| 112 |
face_samples_most_frequent, face_samples_others,
|
| 113 |
aligned_faces_folder_store, frames_folder_store,
|
| 114 |
-
mse_heatmap_embeddings_store, mse_heatmap_posture_store
|
| 115 |
-
annotated_video_output
|
| 116 |
]
|
| 117 |
).then(
|
| 118 |
lambda: gr.Group(visible=True),
|
|
|
|
| 3 |
from video_processing import process_video
|
| 4 |
from PIL import Image
|
| 5 |
import matplotlib
|
|
|
|
| 6 |
matplotlib.rcParams['figure.dpi'] = 500
|
| 7 |
matplotlib.rcParams['savefig.dpi'] = 500
|
| 8 |
|
|
|
|
| 14 |
|
| 15 |
if isinstance(results[0], str) and results[0].startswith("Error"):
|
| 16 |
print(f"Error occurred: {results[0]}")
|
| 17 |
+
return [results[0]] + [None] * 18
|
| 18 |
|
| 19 |
exec_time, results_summary, df, mse_embeddings, mse_posture, \
|
| 20 |
mse_plot_embeddings, mse_histogram_embeddings, \
|
|
|
|
| 22 |
mse_heatmap_embeddings, mse_heatmap_posture, \
|
| 23 |
face_samples_frequent, face_samples_other, \
|
| 24 |
anomaly_faces_embeddings, anomaly_frames_posture_images, \
|
| 25 |
+
aligned_faces_folder, frames_folder = results
|
| 26 |
|
| 27 |
anomaly_faces_embeddings_pil = [Image.fromarray(face) for face in anomaly_faces_embeddings]
|
| 28 |
anomaly_frames_posture_pil = [Image.fromarray(frame) for frame in anomaly_frames_posture_images]
|
|
|
|
| 39 |
anomaly_faces_embeddings_pil, anomaly_frames_posture_pil,
|
| 40 |
face_samples_frequent, face_samples_other,
|
| 41 |
aligned_faces_folder, frames_folder,
|
| 42 |
+
mse_embeddings, mse_posture,
|
| 43 |
]
|
| 44 |
|
| 45 |
return output
|
|
|
|
| 49 |
print(error_message)
|
| 50 |
import traceback
|
| 51 |
traceback.print_exc()
|
| 52 |
+
return [error_message] + [None] * 18
|
| 53 |
|
| 54 |
with gr.Blocks() as iface:
|
| 55 |
gr.Markdown("""
|
| 56 |
+
# Facial Expression and Body Language Anomaly Detection
|
| 57 |
|
| 58 |
+
This application analyzes videos to detect anomalies in facial features and body language.
|
| 59 |
+
It processes the video frames to extract facial embeddings and body posture,
|
| 60 |
+
then uses machine learning techniques to identify unusual patterns or deviations from the norm.
|
| 61 |
+
|
| 62 |
+
For more information, visit: [https://github.com/reab5555/Facial-Expression-Anomaly-Detection](https://github.com/reab5555/Facial-Expression-Anomaly-Detection)
|
| 63 |
""")
|
| 64 |
|
| 65 |
with gr.Row():
|
|
|
|
| 86 |
mse_posture_heatmap = gr.Plot(label="MSE Heatmap: Body Posture")
|
| 87 |
anomaly_frames_posture = gr.Gallery(label="Anomaly Frames (Body Posture)", columns=6, rows=2, height="auto")
|
| 88 |
|
|
|
|
|
|
|
|
|
|
| 89 |
with gr.Tab("Face Samples"):
|
| 90 |
face_samples_most_frequent = gr.Gallery(label="Most Frequent Person Samples (Target)", columns=6, rows=2, height="auto")
|
| 91 |
face_samples_others = gr.Gallery(label="Other Persons Samples", columns=6, rows=1, height="auto")
|
|
|
|
| 110 |
anomaly_frames_features, anomaly_frames_posture,
|
| 111 |
face_samples_most_frequent, face_samples_others,
|
| 112 |
aligned_faces_folder_store, frames_folder_store,
|
| 113 |
+
mse_heatmap_embeddings_store, mse_heatmap_posture_store
|
|
|
|
| 114 |
]
|
| 115 |
).then(
|
| 116 |
lambda: gr.Group(visible=True),
|