viswanani commited on
Commit
d6d8b93
Β·
verified Β·
1 Parent(s): f2ebd8c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -44
app.py CHANGED
@@ -1,52 +1,12 @@
1
  import gradio as gr
2
- import cv2
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-Processed Output"),
48
- title="🏏 GullyDRS - DRS Video Ball Tracker",
49
- description="Upload a cricket delivery video. The app will detect and track the ball using YOLOv8, overlay its path, and return a processed video."
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__":