multimodalart HF Staff commited on
Commit
5ed282c
·
verified ·
1 Parent(s): 98102a6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -27
app.py CHANGED
@@ -13,7 +13,7 @@ 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, max_dimension=832):
17
  """Calculate optimal resolution preserving aspect ratio"""
18
  # Ensure dimensions are multiples of 16
19
  def round_to_16(x):
@@ -24,40 +24,45 @@ def calculate_resolution(input_width, input_height, max_dimension=832):
24
 
25
  # Square videos
26
  if 0.95 <= aspect_ratio <= 1.05:
27
- return 512, 512
28
 
29
  # Landscape videos (width > height)
30
  elif aspect_ratio > 1:
31
- if input_width > input_height:
32
- # Fit to max width
33
- new_width = min(max_dimension, input_width)
34
- new_height = int(new_width / aspect_ratio)
 
 
 
 
35
 
36
- # Ensure height doesn't exceed max
37
- if new_height > 480:
38
- new_height = 480
39
- new_width = int(new_height * aspect_ratio)
40
- else:
41
- new_width = max_dimension
42
- new_height = int(new_width / aspect_ratio)
43
 
44
- # Portrait videos (height > width)
45
  else:
46
- if input_height > input_width:
47
- # Fit to max height
48
- new_height = min(max_dimension, input_height)
49
- new_width = int(new_height * aspect_ratio)
 
 
 
 
50
 
51
- # Ensure width doesn't exceed max
52
- if new_width > 480:
53
- new_width = 480
54
- new_height = int(new_width / aspect_ratio)
55
- else:
56
- new_height = max_dimension
57
- new_width = int(new_height * aspect_ratio)
 
58
 
59
- # Round to multiples of 16
60
- return round_to_16(new_width), round_to_16(new_height)
61
 
62
  @spaces.GPU(duration=90)
63
  def process_video(
 
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"""
18
  # Ensure dimensions are multiples of 16
19
  def round_to_16(x):
 
24
 
25
  # Square videos
26
  if 0.95 <= aspect_ratio <= 1.05:
27
+ return 640, 640
28
 
29
  # Landscape videos (width > height)
30
  elif aspect_ratio > 1:
31
+ # Start with max width
32
+ new_width = max_dimension
33
+ new_height = int(new_width / aspect_ratio)
34
+
35
+ # If height is too small, use min height instead
36
+ if new_height < min_dimension:
37
+ new_height = min_dimension
38
+ new_width = int(new_height * aspect_ratio)
39
 
40
+ # Clamp width if needed
41
+ if new_width > max_dimension:
42
+ new_width = max_dimension
43
+ new_height = int(new_width / aspect_ratio)
 
 
 
44
 
45
+ # Portrait videos (height > width)
46
  else:
47
+ # Start with max height
48
+ new_height = max_dimension
49
+ new_width = int(new_height * aspect_ratio)
50
+
51
+ # If width is too small, use min width instead
52
+ if new_width < min_dimension:
53
+ new_width = min_dimension
54
+ new_height = int(new_width / aspect_ratio)
55
 
56
+ # Clamp height if needed
57
+ if new_height > max_dimension:
58
+ new_height = max_dimension
59
+ new_width = int(new_height / aspect_ratio)
60
+
61
+ # Round to multiples of 16 and ensure within bounds
62
+ final_width = round_to_16(max(min_dimension, min(max_dimension, new_width)))
63
+ final_height = round_to_16(max(min_dimension, min(max_dimension, new_height)))
64
 
65
+ return final_width, final_height
 
66
 
67
  @spaces.GPU(duration=90)
68
  def process_video(