Future-Tense commited on
Commit
bd00d70
1 Parent(s): 9ee1fa9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -37
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
- ret, frame_bgr = player.read(int(frame_num))
45
- frame = cv2.cvtColor(frame_bgr, cv2.COLOR_BGR2RGB)
46
- results = model.predict(frame)
47
- render = render_result(model=model, image=frame, result=results[0])
48
- return render
49
- def fw_fn(cur,last):
50
- if not int(cur)+1 > int(last):
51
- next = int(cur)+1
52
- else:
53
- next = last
54
- pass
55
- return next
56
- def bk_fn(cur):
57
- if not int(cur)-1 < 0:
58
- next = int(cur)-1
59
- else:
60
- next = 0
61
- pass
62
- return next
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}")