fcernafukuzaki commited on
Commit
ba801de
·
verified ·
1 Parent(s): e163116

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ from ultralytics import YOLO
3
+ import gradio as gr
4
+
5
+ # Load the YOLOv8 model
6
+ model = YOLO('best.pt')
7
+
8
+ # Define the Gradio interface
9
+ def yolo_tracking(frame):
10
+ # Run YOLOv8 tracking on the frame
11
+ results = model.track(frame, persist=True)
12
+
13
+ # Visualize the results on the frame
14
+ annotated_frame = results[0].plot()
15
+
16
+ # Convert the frame to RGB for Gradio display
17
+ rgb_frame = cv2.cvtColor(annotated_frame, cv2.COLOR_BGR2RGB)
18
+
19
+ return rgb_frame
20
+
21
+ # Create the Gradio interface
22
+ interface = gr.Interface(fn=yolo_tracking, inputs=gr.Video(source="webcam"), outputs=gr.Image(title="YOLOv8 Tracking"))
23
+
24
+ # Launch the Gradio interface
25
+ interface.launch()