openfree commited on
Commit
31bfd8c
1 Parent(s): e948d4d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -13
app.py CHANGED
@@ -532,20 +532,18 @@ def process_input(input_image, upscale_factor, **kwargs):
532
 
533
  was_resized = False
534
 
535
- if w * h * upscale_factor**2 > MAX_PIXEL_BUDGET:
536
- warnings.warn(
537
- f"Requested output image is too large ({w * upscale_factor}x{h * upscale_factor}). Resizing to ({int(aspect_ratio * MAX_PIXEL_BUDGET ** 0.5 // upscale_factor), int(MAX_PIXEL_BUDGET ** 0.5 // aspect_ratio // upscale_factor)}) pixels."
538
- )
539
- gr.Info(
540
- f"Requested output image is too large ({w * upscale_factor}x{h * upscale_factor}). Resizing input to ({int(aspect_ratio * MAX_PIXEL_BUDGET ** 0.5 // upscale_factor), int(MAX_PIXEL_BUDGET ** 0.5 // aspect_ratio // upscale_factor)}) pixels budget."
541
- )
542
- input_image = input_image.resize(
543
- (
544
- int(aspect_ratio * MAX_PIXEL_BUDGET**0.5 // upscale_factor),
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