Update app.py
Browse files
app.py
CHANGED
@@ -1,35 +1,37 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import os
|
3 |
-
import tempfile
|
4 |
-
from Fight_detec_func import fight_detec
|
5 |
-
from objec_detect_yolo import detection
|
6 |
-
|
7 |
-
def analyze_video(video_file):
|
8 |
-
# Save uploaded file to temp location
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
import tempfile
|
4 |
+
from Fight_detec_func import fight_detec
|
5 |
+
from objec_detect_yolo import detection
|
6 |
+
|
7 |
+
def analyze_video(video_file):
|
8 |
+
# Save uploaded file to temp location
|
9 |
+
def analyze_video(video_file):
|
10 |
+
temp_dir = "/tmp"
|
11 |
+
video_path = os.path.join(temp_dir, os.path.basename(video_file)) # ✅ fix
|
12 |
+
|
13 |
+
with open(video_path, 'wb') as f:
|
14 |
+
f.write(video_file.read())
|
15 |
+
|
16 |
+
# Run both detection functions
|
17 |
+
fight_result = fight_detec(video_path, debug=False)
|
18 |
+
yolo_result = detection(video_path)
|
19 |
+
|
20 |
+
# Clean up
|
21 |
+
os.remove(video_path)
|
22 |
+
os.rmdir(temp_dir)
|
23 |
+
|
24 |
+
return {
|
25 |
+
"Fight Detection": fight_result[0],
|
26 |
+
"YOLO Object Detection": yolo_result
|
27 |
+
}
|
28 |
+
|
29 |
+
iface = gr.Interface(
|
30 |
+
fn=analyze_video,
|
31 |
+
inputs=gr.Video(label="Upload Video"),
|
32 |
+
outputs=gr.JSON(label="Detection Results"),
|
33 |
+
title="Fight and Object Detection System",
|
34 |
+
description="Upload a video to detect fights and objects using our AI models"
|
35 |
+
)
|
36 |
+
|
37 |
+
iface.launch()
|