KillD00zer commited on
Commit
f68e74f
·
verified ·
1 Parent(s): a1beb07

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -35
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
- temp_dir = tempfile.mkdtemp()
10
- video_path = os.path.join(temp_dir, video_file.name)
11
- with open(video_path, 'wb') as f:
12
- f.write(video_file.read())
13
-
14
- # Run both detection functions
15
- fight_result = fight_detec(video_path, debug=False)
16
- yolo_result = detection(video_path)
17
-
18
- # Clean up
19
- os.remove(video_path)
20
- os.rmdir(temp_dir)
21
-
22
- return {
23
- "Fight Detection": fight_result[0],
24
- "YOLO Object Detection": yolo_result
25
- }
26
-
27
- iface = gr.Interface(
28
- fn=analyze_video,
29
- inputs=gr.Video(label="Upload Video"),
30
- outputs=gr.JSON(label="Detection Results"),
31
- title="Fight and Object Detection System",
32
- description="Upload a video to detect fights and objects using our AI models"
33
- )
34
-
35
- iface.launch()
 
 
 
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()