Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -65,13 +65,15 @@ def capture_function(vid=None):
|
|
| 65 |
fbox=[]
|
| 66 |
cnt=0
|
| 67 |
frame_count1= int(frame_count)
|
| 68 |
-
for i in range(int(frame_count1)):
|
| 69 |
capture.set(cv2.CAP_PROP_POS_FRAMES, i)
|
| 70 |
ret, frame_f = capture.read(i)
|
| 71 |
#frame_ff = cv2.cvtColor(frame_f, cv2.COLOR_BGR2RGB)
|
| 72 |
cv2.imwrite(f'{uid}-frames/{i}.png',frame_f)
|
| 73 |
fbox.append(f'{uid}-frames/{i}.png')
|
| 74 |
-
|
|
|
|
|
|
|
| 75 |
|
| 76 |
def im_2_vid(images,fps):
|
| 77 |
#width, height = Image.open(images[0]).size
|
|
@@ -147,7 +149,10 @@ def trim_vid(vid,start_time,end_time):
|
|
| 147 |
#vid = f"{inp_out}.mp4"
|
| 148 |
ffmpeg_extract_subclip(vid, start, end, targetname=f"{uid}-clip.mp4")
|
| 149 |
out= f"{uid}-clip.mp4"
|
| 150 |
-
|
|
|
|
|
|
|
|
|
|
| 151 |
|
| 152 |
def other():
|
| 153 |
new_video_in = str(vid)
|
|
@@ -184,12 +189,16 @@ with gr.Blocks() as app:
|
|
| 184 |
with gr.Row():
|
| 185 |
start_f = gr.Textbox(label = "Start", value = "0:00:00", placeholder = "0:00:23",interactive = True)
|
| 186 |
end_f = gr.Textbox(label = "End", value = "0:00:05", placeholder = "0:00:54",interactive = True)
|
|
|
|
| 187 |
trim_btn=gr.Button("Trim")
|
| 188 |
out_trim=gr.Video(format="mp4")
|
| 189 |
hid_box = gr.Textbox(visible=False)
|
| 190 |
|
| 191 |
with gr.Tab("Frames"):
|
| 192 |
-
|
|
|
|
|
|
|
|
|
|
| 193 |
with gr.Row():
|
| 194 |
with gr.Column():
|
| 195 |
frame_gal = gr.Gallery(columns=6)
|
|
@@ -214,9 +223,9 @@ with gr.Blocks() as app:
|
|
| 214 |
def echo_fn(inp):
|
| 215 |
return inp
|
| 216 |
#outp_vid.change(echo_fn,outp_vid,[out_trim])
|
| 217 |
-
trim_btn.click(trim_vid,[hid_box,start_f,end_f],[out_trim,in_vid])
|
| 218 |
outp_vid.change(load_video,outp_vid,[frame_count,fps,end_f]).then(echo_fn,outp_vid,[out_trim])
|
| 219 |
-
frame_btn.click(capture_function,[out_trim],[frame_gal,frame_file])
|
| 220 |
rem_btn.click(rem_bg,[out_trim],[rem_vid,frame_num,rem_bg_vid])
|
| 221 |
go_btn.click(dl,inp_url,[outp_vid,outp_file,out_trim,hid_box])
|
| 222 |
app.load(fn=predict, inputs=[text_input,url_params], outputs=[text_output,text_input],_js=load_js)
|
|
|
|
| 65 |
fbox=[]
|
| 66 |
cnt=0
|
| 67 |
frame_count1= int(frame_count)
|
| 68 |
+
for i in range(int(frame_count1)-1):
|
| 69 |
capture.set(cv2.CAP_PROP_POS_FRAMES, i)
|
| 70 |
ret, frame_f = capture.read(i)
|
| 71 |
#frame_ff = cv2.cvtColor(frame_f, cv2.COLOR_BGR2RGB)
|
| 72 |
cv2.imwrite(f'{uid}-frames/{i}.png',frame_f)
|
| 73 |
fbox.append(f'{uid}-frames/{i}.png')
|
| 74 |
+
frame_num=f'Working on {i+1} of {frame_count1-1}'
|
| 75 |
+
|
| 76 |
+
yield fbox,fbox,frame_num
|
| 77 |
|
| 78 |
def im_2_vid(images,fps):
|
| 79 |
#width, height = Image.open(images[0]).size
|
|
|
|
| 149 |
#vid = f"{inp_out}.mp4"
|
| 150 |
ffmpeg_extract_subclip(vid, start, end, targetname=f"{uid}-clip.mp4")
|
| 151 |
out= f"{uid}-clip.mp4"
|
| 152 |
+
capture = cv2.VideoCapture(out)
|
| 153 |
+
frame_count = int(capture.get(cv2.CAP_PROP_FRAME_COUNT))
|
| 154 |
+
capture.release()
|
| 155 |
+
return out,out,frame_count
|
| 156 |
|
| 157 |
def other():
|
| 158 |
new_video_in = str(vid)
|
|
|
|
| 189 |
with gr.Row():
|
| 190 |
start_f = gr.Textbox(label = "Start", value = "0:00:00", placeholder = "0:00:23",interactive = True)
|
| 191 |
end_f = gr.Textbox(label = "End", value = "0:00:05", placeholder = "0:00:54",interactive = True)
|
| 192 |
+
trim_count = gr.Textbox(label="Trimmed Frames")
|
| 193 |
trim_btn=gr.Button("Trim")
|
| 194 |
out_trim=gr.Video(format="mp4")
|
| 195 |
hid_box = gr.Textbox(visible=False)
|
| 196 |
|
| 197 |
with gr.Tab("Frames"):
|
| 198 |
+
with gr.Row():
|
| 199 |
+
frame_btn = gr.Button("Get Frames")
|
| 200 |
+
frame_num=gr.Textbox("Status")
|
| 201 |
+
|
| 202 |
with gr.Row():
|
| 203 |
with gr.Column():
|
| 204 |
frame_gal = gr.Gallery(columns=6)
|
|
|
|
| 223 |
def echo_fn(inp):
|
| 224 |
return inp
|
| 225 |
#outp_vid.change(echo_fn,outp_vid,[out_trim])
|
| 226 |
+
trim_btn.click(trim_vid,[hid_box,start_f,end_f],[out_trim,in_vid,trim_count])
|
| 227 |
outp_vid.change(load_video,outp_vid,[frame_count,fps,end_f]).then(echo_fn,outp_vid,[out_trim])
|
| 228 |
+
frame_btn.click(capture_function,[out_trim],[frame_gal,frame_file,frame_stat])
|
| 229 |
rem_btn.click(rem_bg,[out_trim],[rem_vid,frame_num,rem_bg_vid])
|
| 230 |
go_btn.click(dl,inp_url,[outp_vid,outp_file,out_trim,hid_box])
|
| 231 |
app.load(fn=predict, inputs=[text_input,url_params], outputs=[text_output,text_input],_js=load_js)
|