Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,21 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import cv2
|
| 3 |
-
import numpy as np
|
| 4 |
-
from ultralytics import YOLO
|
| 5 |
import tempfile
|
|
|
|
| 6 |
|
| 7 |
# Load YOLOv8 model
|
| 8 |
model = YOLO("yolov8n.pt")
|
| 9 |
|
| 10 |
# Function for object detection + tracking
|
| 11 |
def detect_and_track(video_file):
|
|
|
|
|
|
|
|
|
|
| 12 |
cap = cv2.VideoCapture(video_file.name)
|
| 13 |
output_path = tempfile.mktemp(suffix=".mp4")
|
| 14 |
|
| 15 |
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
| 16 |
-
fps = cap.get(cv2.CAP_PROP_FPS)
|
| 17 |
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
| 18 |
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
| 19 |
|
|
@@ -30,16 +32,20 @@ def detect_and_track(video_file):
|
|
| 30 |
|
| 31 |
cap.release()
|
| 32 |
out.release()
|
| 33 |
-
return output_path
|
| 34 |
|
| 35 |
# Gradio UI
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
if __name__ == "__main__":
|
| 45 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import cv2
|
|
|
|
|
|
|
| 3 |
import tempfile
|
| 4 |
+
from ultralytics import YOLO
|
| 5 |
|
| 6 |
# Load YOLOv8 model
|
| 7 |
model = YOLO("yolov8n.pt")
|
| 8 |
|
| 9 |
# Function for object detection + tracking
|
| 10 |
def detect_and_track(video_file):
|
| 11 |
+
if video_file is None:
|
| 12 |
+
return None
|
| 13 |
+
|
| 14 |
cap = cv2.VideoCapture(video_file.name)
|
| 15 |
output_path = tempfile.mktemp(suffix=".mp4")
|
| 16 |
|
| 17 |
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
| 18 |
+
fps = cap.get(cv2.CAP_PROP_FPS) or 25.0
|
| 19 |
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
| 20 |
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
| 21 |
|
|
|
|
| 32 |
|
| 33 |
cap.release()
|
| 34 |
out.release()
|
| 35 |
+
return output_path # must return path for gr.Video
|
| 36 |
|
| 37 |
# Gradio UI
|
| 38 |
+
with gr.Blocks() as demo:
|
| 39 |
+
gr.Markdown("# 🎯 FullTrack AI - Object Tracking\nUpload a video to run YOLOv8 tracking with trajectory predictions.")
|
| 40 |
+
|
| 41 |
+
with gr.Row():
|
| 42 |
+
with gr.Column():
|
| 43 |
+
video_in = gr.File(label="Upload a Video", file_types=[".mp4", ".avi", ".mov"])
|
| 44 |
+
btn = gr.Button("Submit", variant="primary")
|
| 45 |
+
with gr.Column():
|
| 46 |
+
video_out = gr.Video(label="Tracked Output")
|
| 47 |
+
|
| 48 |
+
btn.click(detect_and_track, inputs=video_in, outputs=video_out)
|
| 49 |
|
| 50 |
if __name__ == "__main__":
|
| 51 |
demo.launch()
|