Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -37,7 +37,11 @@ def load_video(vid):
|
|
37 |
minutes = int(vid_t/60)-(hours*360)
|
38 |
seconds = vid_t-(minutes*60)-(hours*360)
|
39 |
vid_len = f'{hours}:{minutes}:{seconds}'
|
40 |
-
|
|
|
|
|
|
|
|
|
41 |
def im_2_vid(images,fps):
|
42 |
this_im=cv2.imread(images[0])
|
43 |
height=this_im.shape[0]
|
@@ -91,6 +95,64 @@ def trim_vid(vid,start_time,end_time):
|
|
91 |
capture.release()
|
92 |
return out,frame_count
|
93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
def gif_clip(program,fps,qual,model_name,denoise_strength,face_enhance,outscale):
|
95 |
_=None
|
96 |
fps=float(fps)
|
@@ -121,15 +183,10 @@ def gif_clip(program,fps,qual,model_name,denoise_strength,face_enhance,outscale)
|
|
121 |
out_url = f'https://omnibus-Vid-2-GIF-ERSGAN.hf.space/file={out}'
|
122 |
mes=f'Improving frame {i+1} of {frame_count}'
|
123 |
yield _,_,mes
|
124 |
-
|
125 |
out = esr(out_url, model_name, float(denoise_strength), face_enhance, int(outscale))
|
126 |
#yield _,_,mes
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
#cv2.imwrite(f'{img}',out)
|
131 |
out_box.append(f'{out}')
|
132 |
-
|
133 |
print (f'https://omnibus-Vid-2-GIF-ERSGAN.hf.space/file={out}')
|
134 |
#print (f'out::{out}')
|
135 |
print (f'out_box::{out_box}')
|
@@ -190,8 +247,15 @@ with gr.Blocks(css=css) as app:
|
|
190 |
with gr.Row():
|
191 |
gr.Column()
|
192 |
with gr.Column():
|
193 |
-
with gr.Box():
|
|
|
|
|
|
|
|
|
|
|
|
|
194 |
with gr.Group():
|
|
|
195 |
inp_url = gr.Textbox(label="Video URL")
|
196 |
go_btn = gr.Button("Run")
|
197 |
outp_vid=gr.Video(format="mp4")
|
@@ -276,7 +340,7 @@ with gr.Blocks(css=css) as app:
|
|
276 |
speed_btn.click(update_speed,[hid_box,clip_speed,hid_fps],[outp_vid,hid_box,outp_file])
|
277 |
gif_btn.click(gif_clip,[choose_prog,fps,qual,model_name,denoise_strength,face_enhance,outscale],[gif_show,gif_file,gif_stat])
|
278 |
trim_btn.click(trim_vid,[hid_box,start_f,end_f],[out_trim,trim_count])
|
279 |
-
outp_vid.change(load_video,outp_vid,[frame_count,fps,end_f,hid_box]).then(trim_vid,[hid_box,start_f,end_f],[out_trim,trim_count])
|
280 |
go_btn.click(dl,[inp_url,outp_vid],[outp_vid,outp_file,out_trim,hid_box,hid_fps])
|
281 |
app.load(fn=predict, inputs=[text_input,url_params], outputs=[text_output,text_input],_js=load_js)
|
282 |
app.launch(show_api=False)
|
|
|
37 |
minutes = int(vid_t/60)-(hours*360)
|
38 |
seconds = vid_t-(minutes*60)-(hours*360)
|
39 |
vid_len = f'{hours}:{minutes}:{seconds}'
|
40 |
+
if ".gif" in new_video_in:
|
41 |
+
idx_vid = gr.update(value="GIF")
|
42 |
+
else:
|
43 |
+
idx_vid = gr.update(value="Video")
|
44 |
+
return frame_count, fps, vid_len, vid,idx_vid
|
45 |
def im_2_vid(images,fps):
|
46 |
this_im=cv2.imread(images[0])
|
47 |
height=this_im.shape[0]
|
|
|
95 |
capture.release()
|
96 |
return out,frame_count
|
97 |
|
98 |
+
|
99 |
+
def video_clip(program,fps,qual,model_name,denoise_strength,face_enhance,outscale):
|
100 |
+
_=None
|
101 |
+
fps=float(fps)
|
102 |
+
new_video_in = str(f"{uid}-clip.mp4")
|
103 |
+
capture = cv2.VideoCapture(new_video_in)
|
104 |
+
frame_count = int(capture.get(cv2.CAP_PROP_FRAME_COUNT))
|
105 |
+
fbox=[]
|
106 |
+
out_box=[]
|
107 |
+
cnt=0
|
108 |
+
frame_count1= int(frame_count)
|
109 |
+
for i in range(int(frame_count1)-1):
|
110 |
+
capture.set(cv2.CAP_PROP_POS_FRAMES, i)
|
111 |
+
ret, frame_f = capture.read(i)
|
112 |
+
#frame_ff = cv2.cvtColor(frame_f, cv2.COLOR_BGR2RGB)
|
113 |
+
cv2.imwrite(f'{uid}-frames/{i+1}.png',frame_f)
|
114 |
+
fbox.append(f'{uid}-frames/{i+1}.png')
|
115 |
+
mes=f'Working on {i+1} of {frame_count1}'
|
116 |
+
yield _,_,mes
|
117 |
+
yield _,_,"Frames Complete"
|
118 |
+
if qual:
|
119 |
+
mes = "Improving Quality"
|
120 |
+
yield _,_,mes
|
121 |
+
if qual:
|
122 |
+
for i,img in enumerate(fbox):
|
123 |
+
#print (img)
|
124 |
+
out = os.path.abspath(img)
|
125 |
+
out_url = f'https://omnibus-Vid-2-GIF-ERSGAN.hf.space/file={out}'
|
126 |
+
mes=f'Improving frame {i+1} of {frame_count}'
|
127 |
+
yield _,_,mes
|
128 |
+
out = esr(out_url, model_name, float(denoise_strength), face_enhance, int(outscale))
|
129 |
+
#yield _,_,mes
|
130 |
+
#cv2.imwrite(f'{img}',out)
|
131 |
+
out_box.append(f'{out}')
|
132 |
+
print (f'https://omnibus-Vid-2-GIF-ERSGAN.hf.space/file={out}')
|
133 |
+
#print (f'out::{out}')
|
134 |
+
print (f'out_box::{out_box}')
|
135 |
+
clip = ImageSequenceClip(out_box, fps = fps)
|
136 |
+
else:
|
137 |
+
mes="Writing Video"
|
138 |
+
clip = ImageSequenceClip(fbox, fps = fps)
|
139 |
+
yield _,_,"Writing Video"
|
140 |
+
|
141 |
+
###################
|
142 |
+
videoclip = VideoFileClip(new_video_in)
|
143 |
+
audioclip=videoclip.audio
|
144 |
+
#clip = moviepy.video.io.ImageSequenceClip.ImageSequenceClip(images, fps)
|
145 |
+
clip.audio=audioclip
|
146 |
+
clip.write_videofile(f"{uid}/enhanced_vid.mp4")
|
147 |
+
########################
|
148 |
+
|
149 |
+
|
150 |
+
|
151 |
+
#clip.speedx(2).to_gif(f"{uid}/clip_gif.gif",program=program)
|
152 |
+
yield _,_,"Saving Video"
|
153 |
+
out = f"{uid}/enhanced_vid.mp4"
|
154 |
+
yield out,out,"Video Complete"
|
155 |
+
|
156 |
def gif_clip(program,fps,qual,model_name,denoise_strength,face_enhance,outscale):
|
157 |
_=None
|
158 |
fps=float(fps)
|
|
|
183 |
out_url = f'https://omnibus-Vid-2-GIF-ERSGAN.hf.space/file={out}'
|
184 |
mes=f'Improving frame {i+1} of {frame_count}'
|
185 |
yield _,_,mes
|
|
|
186 |
out = esr(out_url, model_name, float(denoise_strength), face_enhance, int(outscale))
|
187 |
#yield _,_,mes
|
|
|
|
|
|
|
188 |
#cv2.imwrite(f'{img}',out)
|
189 |
out_box.append(f'{out}')
|
|
|
190 |
print (f'https://omnibus-Vid-2-GIF-ERSGAN.hf.space/file={out}')
|
191 |
#print (f'out::{out}')
|
192 |
print (f'out_box::{out_box}')
|
|
|
247 |
with gr.Row():
|
248 |
gr.Column()
|
249 |
with gr.Column():
|
250 |
+
#with gr.Box():
|
251 |
+
with gr.Tab("Image"):
|
252 |
+
with gr.Group():
|
253 |
+
inp_img_url=gr.Textbox(label="Image URL")
|
254 |
+
inp_img=gr.Image(label = "Input Image"):
|
255 |
+
outp_img=gr.Image(label="Enhanced Image")
|
256 |
+
with gr.Tab("Video/GIF"):
|
257 |
with gr.Group():
|
258 |
+
idx_vid=gr.Radio(choices=["Video","GIF"])
|
259 |
inp_url = gr.Textbox(label="Video URL")
|
260 |
go_btn = gr.Button("Run")
|
261 |
outp_vid=gr.Video(format="mp4")
|
|
|
340 |
speed_btn.click(update_speed,[hid_box,clip_speed,hid_fps],[outp_vid,hid_box,outp_file])
|
341 |
gif_btn.click(gif_clip,[choose_prog,fps,qual,model_name,denoise_strength,face_enhance,outscale],[gif_show,gif_file,gif_stat])
|
342 |
trim_btn.click(trim_vid,[hid_box,start_f,end_f],[out_trim,trim_count])
|
343 |
+
outp_vid.change(load_video,outp_vid,[frame_count,fps,end_f,hid_box,idx_vid]).then(trim_vid,[hid_box,start_f,end_f],[out_trim,trim_count])
|
344 |
go_btn.click(dl,[inp_url,outp_vid],[outp_vid,outp_file,out_trim,hid_box,hid_fps])
|
345 |
app.load(fn=predict, inputs=[text_input,url_params], outputs=[text_output,text_input],_js=load_js)
|
346 |
app.launch(show_api=False)
|