Spaces:
Running
on
Zero
Running
on
Zero
Update utils.py
Browse files
utils.py
CHANGED
|
@@ -11,10 +11,10 @@ captioner_processor = None
|
|
| 11 |
captioner_model = None
|
| 12 |
|
| 13 |
def resize_image_to_1mp(image):
|
| 14 |
-
"""Resizes image to approx 1MP (e.g.,
|
| 15 |
image = image.convert("RGB")
|
| 16 |
w, h = image.size
|
| 17 |
-
target_pixels =
|
| 18 |
aspect_ratio = w / h
|
| 19 |
|
| 20 |
# Calculate new dimensions
|
|
@@ -22,11 +22,11 @@ def resize_image_to_1mp(image):
|
|
| 22 |
new_w = int(new_h * aspect_ratio)
|
| 23 |
|
| 24 |
# Ensure divisibility by 48 for efficiency
|
| 25 |
-
new_w = (new_w //
|
| 26 |
-
new_h = (new_h //
|
| 27 |
|
| 28 |
if new_w == 0 or new_h == 0:
|
| 29 |
-
new_w, new_h =
|
| 30 |
|
| 31 |
return image.resize((new_w, new_h), Image.LANCZOS)
|
| 32 |
|
|
|
|
| 11 |
captioner_model = None
|
| 12 |
|
| 13 |
def resize_image_to_1mp(image):
|
| 14 |
+
"""Resizes image to approx 1MP (e.g., 768x768) preserving aspect ratio."""
|
| 15 |
image = image.convert("RGB")
|
| 16 |
w, h = image.size
|
| 17 |
+
target_pixels = 768 * 768
|
| 18 |
aspect_ratio = w / h
|
| 19 |
|
| 20 |
# Calculate new dimensions
|
|
|
|
| 22 |
new_w = int(new_h * aspect_ratio)
|
| 23 |
|
| 24 |
# Ensure divisibility by 48 for efficiency
|
| 25 |
+
new_w = (new_w // 64) * 64
|
| 26 |
+
new_h = (new_h // 64) * 64
|
| 27 |
|
| 28 |
if new_w == 0 or new_h == 0:
|
| 29 |
+
new_w, new_h = 768 * 768 # Fallback
|
| 30 |
|
| 31 |
return image.resize((new_w, new_h), Image.LANCZOS)
|
| 32 |
|