AjaykumarPilla commited on
Commit
4efd841
·
verified ·
1 Parent(s): 5928482

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -0
app.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import cv2
3
+ import numpy as np
4
+ from transformers import DetrForObjectDetection, DetrImageProcessor
5
+ import librosa
6
+ import matplotlib.pyplot as plt
7
+
8
+ # Load pre-trained model for ball detection
9
+ processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50")
10
+ model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50")
11
+
12
+ def process_drs_video(video_path, audio_path=None):
13
+ # Extract frames from video
14
+ cap = cv2.VideoCapture(video_path)
15
+ frames = []
16
+ while cap.isOpened():
17
+ ret, frame = cap.read()
18
+ if not ret:
19
+ break
20
+ frames.append(frame)
21
+ cap.release()
22
+
23
+ # Detect ball in frames (simplified)
24
+ ball_positions = []
25
+ for frame in frames:
26
+ inputs = processor(images=frame, return_tensors="pt")
27
+ outputs = model(**inputs)
28
+ # Process outputs to get ball coordinates (custom logic needed)
29
+ ball_positions.append([100, 200]) # Placeholder
30
+
31
+ # Predict trajectory (simplified linear model)
32
+ trajectory = np.array(ball_positions) # Replace with actual model
33
+
34
+ # Audio processing for edge detection
35
+ if audio_path:
36
+ y, sr = librosa.load(audio_path)
37
+ onset_env = librosa.onset.onset_strength(y=y, sr=sr)
38
+ edge_detected = np.max(onset_env) > 0.5 # Simplified threshold
39
+
40
+ # LBW decision logic
41
+ decision = "Out" if trajectory[-1][1] < 300 and not edge_detected else "Not Out"
42
+
43
+ # Visualize trajectory
44
+ plt.plot(trajectory[:, 0], trajectory[:, 1], 'r-')
45
+ plt.title(f"DRS Decision: {decision}")
46
+ plt.savefig("trajectory.png")
47
+
48
+ return decision, "trajectory.png"
49
+
50
+ # Gradio interface
51
+ iface = gr.Interface(
52
+ fn=process_drs_video,
53
+ inputs=[gr.Video(label="Upload Delivery Video"), gr.Audio(label="Upload Stump Mic Audio")],
54
+ outputs=[gr.Textbox(label="Decision"), gr.Image(label="Trajectory")],
55
+ title="Cricket DRS Demo"
56
+ )
57
+ iface.launch()