Spaces:
Runtime error
Runtime error
Commit
·
bd00d70
1
Parent(s):
9ee1fa9
Update app.py
Browse files
app.py
CHANGED
@@ -23,45 +23,44 @@ model.overrides['max_det'] = 1000 # maximum number of detections per image
|
|
23 |
model.to(device)
|
24 |
|
25 |
|
26 |
-
with gr.Blocks() as app:
|
27 |
-
stream = gr.State()
|
28 |
-
def load(URL):
|
29 |
-
yt = YouTube(URL)
|
30 |
-
vid_cap = yt.streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().last().download(filename="tmp.mp4")
|
31 |
-
process = cv2.VideoCapture(vid_cap)
|
32 |
-
frame_num = int(process.get(cv2.CAP_PROP_POS_FRAMES))
|
33 |
-
frame_count = int(process.get(cv2.CAP_PROP_FRAME_COUNT))
|
34 |
-
frame_fps = (process.get(cv2.CAP_PROP_FPS))
|
35 |
-
process.release()
|
36 |
-
|
37 |
-
return vid_cap,frame_num,frame_count,frame_fps
|
38 |
-
|
39 |
-
def vid_play(cap,frame_num):
|
40 |
-
player = cv2.VideoCapture(cap)
|
41 |
-
assert player.isOpened() # Make sure that their is a stream.
|
42 |
-
player.set(cv2.CAP_PROP_POS_FRAMES, int(frame_num))
|
43 |
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
|
|
|
|
|
|
65 |
with gr.Row():
|
66 |
with gr.Column():
|
67 |
youtube_url = gr.Textbox(label="YouTube URL",value=f"{URL}")
|
|
|
23 |
model.to(device)
|
24 |
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
+
def load(URL):
|
28 |
+
yt = YouTube(URL)
|
29 |
+
vid_cap = yt.streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().last().download(filename="tmp.mp4")
|
30 |
+
process = cv2.VideoCapture(vid_cap)
|
31 |
+
frame_num = int(process.get(cv2.CAP_PROP_POS_FRAMES))
|
32 |
+
frame_count = int(process.get(cv2.CAP_PROP_FRAME_COUNT))
|
33 |
+
frame_fps = (process.get(cv2.CAP_PROP_FPS))
|
34 |
+
process.release()
|
35 |
+
|
36 |
+
return vid_cap,frame_num,frame_count,frame_fps
|
37 |
+
|
38 |
+
def vid_play(cap,frame_num):
|
39 |
+
player = cv2.VideoCapture(cap)
|
40 |
+
assert player.isOpened() # Make sure that their is a stream.
|
41 |
+
player.set(cv2.CAP_PROP_POS_FRAMES, int(frame_num))
|
42 |
+
|
43 |
+
ret, frame_bgr = player.read(int(frame_num))
|
44 |
+
frame = cv2.cvtColor(frame_bgr, cv2.COLOR_BGR2RGB)
|
45 |
+
results = model.predict(frame)
|
46 |
+
render = render_result(model=model, image=frame, result=results[0])
|
47 |
+
return render
|
48 |
+
def fw_fn(cur,last):
|
49 |
+
next = cur+1
|
50 |
+
if next > last:
|
51 |
+
next = last
|
52 |
+
return next
|
53 |
+
def bk_fn(cur):
|
54 |
+
next = cur-1
|
55 |
+
if next < 0:
|
56 |
+
next = 0
|
57 |
+
return next
|
58 |
+
|
59 |
+
|
60 |
|
61 |
+
|
62 |
+
|
63 |
+
with gr.Blocks() as app:
|
64 |
with gr.Row():
|
65 |
with gr.Column():
|
66 |
youtube_url = gr.Textbox(label="YouTube URL",value=f"{URL}")
|