Omnibus commited on
Commit
4cb2e31
1 Parent(s): b4db0f6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -20
app.py CHANGED
@@ -193,21 +193,12 @@ def gif_clip(program,fps,qual,model_name,denoise_strength,face_enhance,outscale,
193
  clip = ImageSequenceClip(out_box, fps = fps)
194
  else:
195
  clip = ImageSequenceClip(fbox, fps = fps)
196
- yield _,_,"Writing"
197
- if idx_vid == "GIF":
198
- clip.speedx(2).to_gif(f"{uid}/clip_gif.gif",program=program)
199
- out = f"{uid}/clip_gif.gif"
200
- yield out,out,"GIF Complete"
201
-
202
- if idx_vid == "Video":
203
- videoclip = VideoFileClip(new_video_in)
204
- audioclip=videoclip.audio
205
- #clip = moviepy.video.io.ImageSequenceClip.ImageSequenceClip(images, fps)
206
- clip.audio=audioclip
207
- clip.write_videofile(f"{uid}/enhanced_vid.mp4")
208
- out = f"{uid}/enhanced_vid.mp4"
209
- yield out,out,"Video Complete"
210
-
211
 
212
  def update_speed(inp,clip_speed,fps):
213
  if "-split.mp4" in inp:
@@ -255,13 +246,13 @@ with gr.Blocks(css=css) as app:
255
  with gr.Row():
256
  gr.Column()
257
  with gr.Column():
258
- #with gr.Box():
259
- with gr.Tab("Image"):
260
  with gr.Group():
261
  inp_img_url=gr.Textbox(label="Image URL")
262
  inp_img=gr.Image(label = "Input Image")
263
  outp_img=gr.Image(label="Enhanced Image")
264
- with gr.Tab("Video/GIF"):
265
  with gr.Group():
266
  idx_vid=gr.Radio(choices=["Video","GIF"])
267
  inp_url = gr.Textbox(label="Video URL")
@@ -303,9 +294,12 @@ with gr.Blocks(css=css) as app:
303
  samp_btn=gr.Button("Get Sample")
304
  samp_im = gr.Image(label="Sample Frame")
305
 
306
- with gr.Row():
307
  gif_btn = gr.Button("Make GIF")
308
  gif_stat=gr.Textbox(label="Status")
 
 
 
309
  with gr.Row():
310
  with gr.Column():
311
  gif_show = gr.Video()
@@ -344,9 +338,33 @@ with gr.Blocks(css=css) as app:
344
  yield _,"Creating Sample Frame"
345
  out = esr(out_url, model_name, float(denoise_strength), face_enhance, int(outscale))
346
  yield out,"Sample Frame Complete"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
347
  samp_btn.click(run_samp,[choose_prog,fps,qual,model_name,denoise_strength,face_enhance,outscale,frame_targ],[samp_im,gif_stat])
348
  speed_btn.click(update_speed,[hid_box,clip_speed,hid_fps],[outp_vid,hid_box,outp_file])
349
- gif_btn.click(gif_clip,[choose_prog,fps,qual,model_name,denoise_strength,face_enhance,outscale,idx_vid],[gif_show,gif_file,gif_stat])
 
 
350
  trim_btn.click(trim_vid,[hid_box,start_f,end_f],[out_trim,trim_count])
351
  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])
352
  go_btn.click(dl,[inp_url,outp_vid],[outp_vid,outp_file,out_trim,hid_box,hid_fps])
 
193
  clip = ImageSequenceClip(out_box, fps = fps)
194
  else:
195
  clip = ImageSequenceClip(fbox, fps = fps)
196
+ yield _,_,"Writing GIF"
197
+ clip.speedx(2).to_gif(f"{uid}/clip_gif.gif",program=program)
198
+ out = f"{uid}/clip_gif.gif"
199
+ yield out,out,"GIF Complete"
200
+
201
+
 
 
 
 
 
 
 
 
 
202
 
203
  def update_speed(inp,clip_speed,fps):
204
  if "-split.mp4" in inp:
 
246
  with gr.Row():
247
  gr.Column()
248
  with gr.Column():
249
+ choose_media = gr.Radio(label="Media Type",choices=["Image","Video","GIF"],value="Image")
250
+ with gr.Box(visible=True) as im_box:
251
  with gr.Group():
252
  inp_img_url=gr.Textbox(label="Image URL")
253
  inp_img=gr.Image(label = "Input Image")
254
  outp_img=gr.Image(label="Enhanced Image")
255
+ with gr.Box(visible=False) as vid_box:
256
  with gr.Group():
257
  idx_vid=gr.Radio(choices=["Video","GIF"])
258
  inp_url = gr.Textbox(label="Video URL")
 
294
  samp_btn=gr.Button("Get Sample")
295
  samp_im = gr.Image(label="Sample Frame")
296
 
297
+ with gr.Row(visible=False) as gif_row:
298
  gif_btn = gr.Button("Make GIF")
299
  gif_stat=gr.Textbox(label="Status")
300
+ with gr.Row(visible=False) as vid_row:
301
+ vid_btn = gr.Button("Make Video")
302
+ vid_stat=gr.Textbox(label="Status")
303
  with gr.Row():
304
  with gr.Column():
305
  gif_show = gr.Video()
 
338
  yield _,"Creating Sample Frame"
339
  out = esr(out_url, model_name, float(denoise_strength), face_enhance, int(outscale))
340
  yield out,"Sample Frame Complete"
341
+
342
+ def new_media(inp):
343
+ if inp == "Image":
344
+ im_box = gr.update(visible=True)
345
+ vid_box = gr.update(visible=False)
346
+ gif_row = gr.update(visible=False)
347
+ vid_row = gr.update(visible=False)
348
+ return (im_box,vid_box,gif_row,vid_row)
349
+ if inp == "Video":
350
+ im_box = gr.update(visible=False)
351
+ vid_box = gr.update(visible=True)
352
+ gif_row = gr.update(visible=False)
353
+ vid_row = gr.update(visible=True)
354
+ return (im_box,vid_box,gif_row,vid_row)
355
+ if inp == "GIF":
356
+ im_box = gr.update(visible=False)
357
+ vid_box = gr.update(visible=True)
358
+ gif_row = gr.update(visible=True)
359
+ vid_row = gr.update(visible=False)
360
+ return (im_box,vid_box,gif_row,vid_row)
361
+
362
+ choose_media.change(new_media,choose_media,[im_box,vid_box,gif_row,vid_row])
363
  samp_btn.click(run_samp,[choose_prog,fps,qual,model_name,denoise_strength,face_enhance,outscale,frame_targ],[samp_im,gif_stat])
364
  speed_btn.click(update_speed,[hid_box,clip_speed,hid_fps],[outp_vid,hid_box,outp_file])
365
+ gif_btn.click(gif_clip,[choose_prog,fps,qual,model_name,denoise_strength,face_enhance,outscale],[gif_show,gif_file,gif_stat])
366
+ vid_btn.click(vid_clip,[choose_prog,fps,qual,model_name,denoise_strength,face_enhance,outscale],[gif_show,gif_file,vid_stat])
367
+
368
  trim_btn.click(trim_vid,[hid_box,start_f,end_f],[out_trim,trim_count])
369
  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])
370
  go_btn.click(dl,[inp_url,outp_vid],[outp_vid,outp_file,out_trim,hid_box,hid_fps])