clementchadebec commited on
Commit
bfd8827
1 Parent(s): da90319

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -3
app.py CHANGED
@@ -56,26 +56,32 @@ def process_input(input_image, upscale_factor, **kwargs):
56
  w_original, h_original = w, h
57
  aspect_ratio = w / h
58
 
 
 
59
  if w * h * upscale_factor**2 > MAX_PIXEL_BUDGET:
60
  warnings.warn(
61
  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."
62
  )
 
 
 
63
  input_image = input_image.resize(
64
  (
65
  int(aspect_ratio * MAX_PIXEL_BUDGET**0.5 // upscale_factor),
66
  int(MAX_PIXEL_BUDGET**0.5 // aspect_ratio // upscale_factor),
67
  )
68
  )
 
69
 
70
  # resize to multiple of 8
71
  w, h = input_image.size
72
  w = w - w % 8
73
  h = h - h % 8
74
 
75
- return input_image.resize((w, h)), w_original, h_original
76
 
77
 
78
- @spaces.GPU
79
  def infer(
80
  seed,
81
  randomize_seed,
@@ -88,7 +94,9 @@ def infer(
88
  if randomize_seed:
89
  seed = random.randint(0, MAX_SEED)
90
  true_input_image = input_image
91
- input_image, w_original, h_original = process_input(input_image, upscale_factor)
 
 
92
 
93
  # rescale with upscale factor
94
  w, h = input_image.size
@@ -107,6 +115,11 @@ def infer(
107
  generator=generator,
108
  ).images[0]
109
 
 
 
 
 
 
110
  # resize to target desired size
111
  image = image.resize((w_original * upscale_factor, h_original * upscale_factor))
112
  image.save("output.jpg")
 
56
  w_original, h_original = w, h
57
  aspect_ratio = w / h
58
 
59
+ was_resized = False
60
+
61
  if w * h * upscale_factor**2 > MAX_PIXEL_BUDGET:
62
  warnings.warn(
63
  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."
64
  )
65
+ gr.Info(
66
+ 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)}) input pixels budget."
67
+ )
68
  input_image = input_image.resize(
69
  (
70
  int(aspect_ratio * MAX_PIXEL_BUDGET**0.5 // upscale_factor),
71
  int(MAX_PIXEL_BUDGET**0.5 // aspect_ratio // upscale_factor),
72
  )
73
  )
74
+ was_resized = True
75
 
76
  # resize to multiple of 8
77
  w, h = input_image.size
78
  w = w - w % 8
79
  h = h - h % 8
80
 
81
+ return input_image.resize((w, h)), w_original, h_original, was_resized
82
 
83
 
84
+ @spaces.GPU(duration=75)
85
  def infer(
86
  seed,
87
  randomize_seed,
 
94
  if randomize_seed:
95
  seed = random.randint(0, MAX_SEED)
96
  true_input_image = input_image
97
+ input_image, w_original, h_original, was_resized = process_input(
98
+ input_image, upscale_factor
99
+ )
100
 
101
  # rescale with upscale factor
102
  w, h = input_image.size
 
115
  generator=generator,
116
  ).images[0]
117
 
118
+ if was_resized:
119
+ gr.Info(
120
+ f"Resized output image to targeted {w_original * upscale_factor}x{h_original * upscale_factor} size."
121
+ )
122
+
123
  # resize to target desired size
124
  image = image.resize((w_original * upscale_factor, h_original * upscale_factor))
125
  image.save("output.jpg")