Spaces:
Runtime error
Runtime error
Future-Tense
commited on
Commit
·
097bdac
1
Parent(s):
b3cf540
Update app.py
Browse files
app.py
CHANGED
@@ -118,10 +118,12 @@ with gr.Blocks() as app:
|
|
118 |
def load(URL):
|
119 |
yt = YouTube(URL)
|
120 |
vid_cap = yt.streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().last().download(filename="tmp.mp4")
|
121 |
-
|
122 |
-
|
|
|
|
|
123 |
|
124 |
-
def vid_play2(cap):
|
125 |
player = cv2.VideoCapture(cap)
|
126 |
|
127 |
#player = stream #Get your video stream.
|
@@ -133,8 +135,8 @@ with gr.Blocks() as app:
|
|
133 |
#y_shape = int(player.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
134 |
#four_cc = cv2.VideoWriter_fourcc(*"MJPG") #Using MJPEG codex
|
135 |
#out = cv2.VideoWriter(out_vid, four_cc, 20,(x_shape, y_shape))
|
136 |
-
|
137 |
-
|
138 |
ret, frame = player.read(frame_num)
|
139 |
results = model.predict(frame)
|
140 |
|
@@ -155,11 +157,13 @@ with gr.Blocks() as app:
|
|
155 |
|
156 |
youtube_url = gr.Textbox(label="YouTube URL",value=f"{URL}")
|
157 |
load_button = gr.Button("Load Video")
|
158 |
-
|
|
|
|
|
159 |
with gr.Row():
|
160 |
output_win = gr.Video()
|
161 |
det_win = gr.Image(source="webcam", streaming=True)
|
162 |
-
load_button.click(load,youtube_url,output_win)
|
163 |
-
run_button.click(vid_play2, [output_win], det_win)
|
164 |
|
165 |
app.launch(enable_queue=False)
|
|
|
118 |
def load(URL):
|
119 |
yt = YouTube(URL)
|
120 |
vid_cap = yt.streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().last().download(filename="tmp.mp4")
|
121 |
+
stream = cv2.VideoCapture(vid_cap)
|
122 |
+
frame_num = stream.get(cv2.CAP_PROP_POS_FRAMES)
|
123 |
+
print (frame_num)
|
124 |
+
return stream,frame_num
|
125 |
|
126 |
+
def vid_play2(cap,frame_num):
|
127 |
player = cv2.VideoCapture(cap)
|
128 |
|
129 |
#player = stream #Get your video stream.
|
|
|
135 |
#y_shape = int(player.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
136 |
#four_cc = cv2.VideoWriter_fourcc(*"MJPG") #Using MJPEG codex
|
137 |
#out = cv2.VideoWriter(out_vid, four_cc, 20,(x_shape, y_shape))
|
138 |
+
player.set(cv2.CAP_PROP_POS_FRAMES, frame_num)
|
139 |
+
|
140 |
ret, frame = player.read(frame_num)
|
141 |
results = model.predict(frame)
|
142 |
|
|
|
157 |
|
158 |
youtube_url = gr.Textbox(label="YouTube URL",value=f"{URL}")
|
159 |
load_button = gr.Button("Load Video")
|
160 |
+
with gr.Row():
|
161 |
+
run_button = gr.Button()
|
162 |
+
cur_frame = gr.Number(value=0)
|
163 |
with gr.Row():
|
164 |
output_win = gr.Video()
|
165 |
det_win = gr.Image(source="webcam", streaming=True)
|
166 |
+
load_button.click(load,youtube_url,[output_win,cur_frame])
|
167 |
+
run_button.click(vid_play2, [output_win,cur_frame], det_win)
|
168 |
|
169 |
app.launch(enable_queue=False)
|