Spaces:
Running
on
Zero
Running
on
Zero
Pierre Chapuis
commited on
downscale input images
Browse fileshttps://huggingface.co/spaces/finegrain/finegrain-image-enhancer/discussions/7
- src/app.py +11 -1
src/app.py
CHANGED
@@ -118,8 +118,18 @@ def process(
|
|
118 |
generator = torch.Generator(device=DEVICE)
|
119 |
generator.manual_seed(seed)
|
120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
enhanced_image = enhancer.upscale(
|
122 |
-
image=
|
123 |
prompt=prompt,
|
124 |
negative_prompt=negative_prompt,
|
125 |
upscale_factor=upscale_factor,
|
|
|
118 |
generator = torch.Generator(device=DEVICE)
|
119 |
generator.manual_seed(seed)
|
120 |
|
121 |
+
# Resize to avoid using too much VRAM.
|
122 |
+
# If you have a bug GPU you can go higher.
|
123 |
+
side_size = min(input_image.size)
|
124 |
+
if side_size > 768:
|
125 |
+
scale = 768 / side_size
|
126 |
+
new_size = (int(input_image.width * scale), int(input_image.height * scale))
|
127 |
+
resized_image = input_image.resize(new_size, resample=Image.Resampling.LANCZOS)
|
128 |
+
else:
|
129 |
+
resized_image = input_image
|
130 |
+
|
131 |
enhanced_image = enhancer.upscale(
|
132 |
+
image=resized_image,
|
133 |
prompt=prompt,
|
134 |
negative_prompt=negative_prompt,
|
135 |
upscale_factor=upscale_factor,
|