Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,52 +1,12 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
-
import os
|
| 4 |
-
import tempfile
|
| 5 |
-
from ultralytics import YOLO
|
| 6 |
|
| 7 |
-
# β
Load the model
|
| 8 |
-
try:
|
| 9 |
-
model = YOLO("best.pt")
|
| 10 |
-
except:
|
| 11 |
-
print("β οΈ Failed to load best.pt, falling back to yolov8n.pt")
|
| 12 |
-
model = YOLO("yolov8n.pt")
|
| 13 |
-
|
| 14 |
-
# β
Core logic: process video frame-by-frame
|
| 15 |
-
def process_video(video_path):
|
| 16 |
-
cap = cv2.VideoCapture(video_path)
|
| 17 |
-
if not cap.isOpened():
|
| 18 |
-
raise Exception("β Failed to open video file")
|
| 19 |
-
|
| 20 |
-
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
| 21 |
-
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
| 22 |
-
fps = int(cap.get(cv2.CAP_PROP_FPS))
|
| 23 |
-
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
| 24 |
-
|
| 25 |
-
# β
Output file path
|
| 26 |
-
out_path = tempfile.NamedTemporaryFile(suffix=".mp4", delete=False).name
|
| 27 |
-
out = cv2.VideoWriter(out_path, fourcc, fps, (width, height))
|
| 28 |
-
|
| 29 |
-
while True:
|
| 30 |
-
ret, frame = cap.read()
|
| 31 |
-
if not ret:
|
| 32 |
-
break
|
| 33 |
-
|
| 34 |
-
results = model(frame)
|
| 35 |
-
annotated = results[0].plot()
|
| 36 |
-
out.write(annotated)
|
| 37 |
-
|
| 38 |
-
cap.release()
|
| 39 |
-
out.release()
|
| 40 |
-
|
| 41 |
-
return out_path
|
| 42 |
-
|
| 43 |
-
# β
Gradio UI
|
| 44 |
demo = gr.Interface(
|
| 45 |
fn=process_video,
|
| 46 |
inputs=gr.Video(label="Upload Cricket Video (.mp4)"),
|
| 47 |
-
outputs=gr.Video(label="DRS
|
| 48 |
-
title="π GullyDRS -
|
| 49 |
-
description="Upload a
|
| 50 |
)
|
| 51 |
|
| 52 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from drs_engine import process_video
|
|
|
|
|
|
|
|
|
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
demo = gr.Interface(
|
| 5 |
fn=process_video,
|
| 6 |
inputs=gr.Video(label="Upload Cricket Video (.mp4)"),
|
| 7 |
+
outputs=gr.Video(label="DRS Result Video"),
|
| 8 |
+
title="π GullyDRS - Ball Tracking & LBW Decision",
|
| 9 |
+
description="Upload a delivery video. This system will track the ball, estimate speed, detect bounce, apply simplified DRS rules, and overlay the decision: OUT or NOT OUT."
|
| 10 |
)
|
| 11 |
|
| 12 |
if __name__ == "__main__":
|