SingleZombie commited on
Commit
826f0e1
1 Parent(s): adefceb

reduce inference time

Browse files
Files changed (2) hide show
  1. app.py +12 -10
  2. src/utils.py +1 -1
app.py CHANGED
@@ -238,13 +238,15 @@ class GlobalState:
238
 
239
 
240
  @torch.no_grad()
241
- @spaces.GPU(duration=240)
242
  def process1(input_path, prompt, sd_model, seed, image_resolution, control_strength,
243
  x0_strength, control_type, low_threshold, high_threshold,
244
  ddpm_steps, scale, a_prompt, n_prompt,
245
  frame_count, batch_size, mininterv, maxinterv,
246
  use_constraints, bg_smooth,
247
  b1, b2, s1, s2):
 
 
248
  global_state = GlobalState()
249
  global_state.update_controlnet_model(control_type)
250
  global_state.update_sd_model(sd_model)
@@ -569,12 +571,18 @@ with block:
569
  b1, b2, s1, s2
570
  ]
571
 
572
- example = gr.Label('')
573
-
574
  with gr.Column():
575
  result_keyframe = gr.Video(label='Output key frame video',
576
  format='mp4',
577
  interactive=False)
 
 
 
 
 
 
 
 
578
 
579
  def input_changed(path):
580
  if path is None:
@@ -601,13 +609,7 @@ with block:
601
  value=frame_count,
602
  maximum=frame_count),
603
  )
604
- example = gr.Examples(
605
- examples=example_list,
606
- inputs=[*ips],
607
- fn=process1,
608
- outputs=[result_keyframe],
609
- cache_examples=True
610
- )
611
 
612
  input_path.change(input_changed, input_path, [
613
  mininterv, maxinterv, frame_count])
 
238
 
239
 
240
  @torch.no_grad()
241
+ @spaces.GPU(duration=300)
242
  def process1(input_path, prompt, sd_model, seed, image_resolution, control_strength,
243
  x0_strength, control_type, low_threshold, high_threshold,
244
  ddpm_steps, scale, a_prompt, n_prompt,
245
  frame_count, batch_size, mininterv, maxinterv,
246
  use_constraints, bg_smooth,
247
  b1, b2, s1, s2):
248
+ image_resolution = min(image_resolution, 512)
249
+ frame_count = min(frame_count, 8)
250
  global_state = GlobalState()
251
  global_state.update_controlnet_model(control_type)
252
  global_state.update_sd_model(sd_model)
 
571
  b1, b2, s1, s2
572
  ]
573
 
 
 
574
  with gr.Column():
575
  result_keyframe = gr.Video(label='Output key frame video',
576
  format='mp4',
577
  interactive=False)
578
+ with gr.Row():
579
+ example = gr.Examples(
580
+ examples=example_list,
581
+ inputs=[*ips],
582
+ fn=process1,
583
+ outputs=[result_keyframe],
584
+ cache_examples=True
585
+ )
586
 
587
  def input_changed(path):
588
  if path is None:
 
609
  value=frame_count,
610
  maximum=frame_count),
611
  )
612
+
 
 
 
 
 
 
613
 
614
  input_path.change(input_changed, input_path, [
615
  mininterv, maxinterv, frame_count])
src/utils.py CHANGED
@@ -40,7 +40,7 @@ def resize_image(input_image, resolution):
40
  H, W, C = input_image.shape
41
  H = float(H)
42
  W = float(W)
43
- k = float(resolution) / min(H, W)
44
  H *= k
45
  W *= k
46
  H = int(np.round(H / 64.0)) * 64
 
40
  H, W, C = input_image.shape
41
  H = float(H)
42
  W = float(W)
43
+ k = float(resolution) / max(H, W)
44
  H *= k
45
  W *= k
46
  H = int(np.round(H / 64.0)) * 64