Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
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
|
| 28 |
|
| 29 |
# Landscape videos (width > height)
|
| 30 |
elif aspect_ratio > 1:
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
-
#
|
| 37 |
-
if
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
else:
|
| 41 |
-
new_width = max_dimension
|
| 42 |
-
new_height = int(new_width / aspect_ratio)
|
| 43 |
|
| 44 |
-
# Portrait videos (height > width)
|
| 45 |
else:
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
-
#
|
| 52 |
-
if
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
| 58 |
|
| 59 |
-
|
| 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(
|