multimodalart HF Staff commited on
Commit
abb9ea5
·
unverified ·
1 Parent(s): 170e83c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -13,11 +13,11 @@ vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", torch_dtype=to
13
  pipe = LucyEditPipeline.from_pretrained(model_id, vae=vae, torch_dtype=torch.bfloat16)
14
  pipe.to("cuda")
15
 
16
- def calculate_resolution(input_width, input_height, min_dimension=480, max_dimension=832):
17
  """Calculate optimal resolution preserving aspect ratio within bounds"""
18
- # Ensure dimensions are multiples of 16
19
- def round_to_16(x):
20
- return max(min_dimension, min(max_dimension, int(round(x / 16.0) * 16)))
21
 
22
  # Get aspect ratio
23
  aspect_ratio = input_width / input_height
@@ -40,7 +40,7 @@ def calculate_resolution(input_width, input_height, min_dimension=480, max_dimen
40
  if new_width > max_dimension:
41
  new_width = max_dimension
42
 
43
- return round_to_16(new_width), round_to_16(new_height)
44
 
45
  # Portrait videos (height > width)
46
  else:
@@ -56,7 +56,7 @@ def calculate_resolution(input_width, input_height, min_dimension=480, max_dimen
56
  if new_height > max_dimension:
57
  new_height = max_dimension
58
 
59
- return round_to_16(new_width), round_to_16(new_height)
60
 
61
 
62
  @spaces.GPU(duration=120)
 
13
  pipe = LucyEditPipeline.from_pretrained(model_id, vae=vae, torch_dtype=torch.bfloat16)
14
  pipe.to("cuda")
15
 
16
+ def calculate_resolution(input_width, input_height, min_dimension=480, max_dimension=832, compatible_round=32):
17
  """Calculate optimal resolution preserving aspect ratio within bounds"""
18
+ # Ensure dimensions are multiples of the compatible rounding
19
+ def round_to(x, compatible_round):
20
+ return max(min_dimension, min(max_dimension, int(round(x / compatible_round) * compatible_round)))
21
 
22
  # Get aspect ratio
23
  aspect_ratio = input_width / input_height
 
40
  if new_width > max_dimension:
41
  new_width = max_dimension
42
 
43
+ return round_to(new_width, compatible_round), round_to(new_height, compatible_round)
44
 
45
  # Portrait videos (height > width)
46
  else:
 
56
  if new_height > max_dimension:
57
  new_height = max_dimension
58
 
59
+ return round_to(new_width, compatible_round), round_to(new_height, compatible_round)
60
 
61
 
62
  @spaces.GPU(duration=120)