Future-Tense commited on
Commit
70da591
·
1 Parent(s): bd00d70

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -2
app.py CHANGED
@@ -44,6 +44,7 @@ def vid_play(cap,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
@@ -55,7 +56,17 @@ def bk_fn(cur):
55
  if next < 0:
56
  next = 0
57
  return next
58
-
 
 
 
 
 
 
 
 
 
 
59
 
60
 
61
 
@@ -77,9 +88,12 @@ with gr.Blocks() as app:
77
  pl = gr.Button("Play")
78
  fw = gr.Button(">")
79
  det_win = gr.Image(source="webcam", streaming=True)
 
 
 
80
  bk.click(bk_fn,[cur_frame],cur_frame)
81
  fw.click(fw_fn,[cur_frame,total_frames],cur_frame)
82
  load_button.click(load,youtube_url,[output_win,cur_frame,total_frames,fps_frames])
83
  run_button.click(vid_play, [output_win,cur_frame], det_win)
84
 
85
- app.launch(enable_queue=False)
 
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
+ player.release()
48
  return render
49
  def fw_fn(cur,last):
50
  next = cur+1
 
56
  if next < 0:
57
  next = 0
58
  return next
59
+ def pl_fn(cap,cur,last,fps,pl_tog):
60
+ player = cv2.VideoCapture(cap)
61
+ #assert player.isOpened() # Make sure that their is a stream.
62
+ player.set(cv2.CAP_PROP_POS_FRAMES, cur)
63
+ ret, frame_bgr = player.read(int(cur))
64
+ frame = cv2.cvtColor(frame_bgr, cv2.COLOR_BGR2RGB)
65
+ if pl_tog ==1:
66
+ cur+=1
67
+ else:
68
+ cur = cur
69
+ return frame,cur
70
 
71
 
72
 
 
88
  pl = gr.Button("Play")
89
  fw = gr.Button(">")
90
  det_win = gr.Image(source="webcam", streaming=True)
91
+ with gr.Row():
92
+ pl_tog=gr.Number()
93
+ pl.click(pl_fn,[output_win,cur_frame,total_frames,fps_frames,pl_tog],det_win,every=0.1)
94
  bk.click(bk_fn,[cur_frame],cur_frame)
95
  fw.click(fw_fn,[cur_frame,total_frames],cur_frame)
96
  load_button.click(load,youtube_url,[output_win,cur_frame,total_frames,fps_frames])
97
  run_button.click(vid_play, [output_win,cur_frame], det_win)
98
 
99
+ app.queue(concurrency_count=10).launch()