Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -532,20 +532,18 @@ def process_input(input_image, upscale_factor, **kwargs):
|
|
532 |
|
533 |
was_resized = False
|
534 |
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
int(MAX_PIXEL_BUDGET**0.5 // aspect_ratio // upscale_factor),
|
546 |
-
)
|
547 |
-
)
|
548 |
was_resized = True
|
|
|
549 |
|
550 |
# resize to multiple of 8
|
551 |
w, h = input_image.size
|
|
|
532 |
|
533 |
was_resized = False
|
534 |
|
535 |
+
max_size = int(np.sqrt(MAX_PIXEL_BUDGET / (upscale_factor ** 2)))
|
536 |
+
if w > max_size or h > max_size:
|
537 |
+
if w > h:
|
538 |
+
w_new = max_size
|
539 |
+
h_new = int(w_new / aspect_ratio)
|
540 |
+
else:
|
541 |
+
h_new = max_size
|
542 |
+
w_new = int(h_new * aspect_ratio)
|
543 |
+
|
544 |
+
input_image = input_image.resize((w_new, h_new), Image.LANCZOS)
|
|
|
|
|
|
|
545 |
was_resized = True
|
546 |
+
gr.Info(f"Input image resized to {w_new}x{h_new} to fit within pixel budget after upscaling.")
|
547 |
|
548 |
# resize to multiple of 8
|
549 |
w, h = input_image.size
|