Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -60,8 +60,11 @@ def process_input(input_image, upscale_factor):
|
|
| 60 |
)
|
| 61 |
target_input_pixels = MAX_PIXEL_BUDGET / (upscale_factor ** 2)
|
| 62 |
scale = (target_input_pixels / (w * h)) ** 0.5
|
| 63 |
-
new_w = int(w * scale)
|
| 64 |
-
new_h = int(h * scale)
|
|
|
|
|
|
|
|
|
|
| 65 |
input_image = input_image.resize((new_w, new_h), resample=Image.LANCZOS)
|
| 66 |
was_resized = True
|
| 67 |
|
|
@@ -163,7 +166,8 @@ def enhance_image(
|
|
| 163 |
)
|
| 164 |
pipe.enable_vae_tiling()
|
| 165 |
pipe.enable_vae_slicing()
|
| 166 |
-
|
|
|
|
| 167 |
|
| 168 |
if USE_ESRGAN:
|
| 169 |
esrgan_path = "4x-UltraSharp.pth"
|
|
@@ -230,7 +234,7 @@ def enhance_image(
|
|
| 230 |
control_image,
|
| 231 |
denoising_strength,
|
| 232 |
num_inference_steps,
|
| 233 |
-
|
| 234 |
generator,
|
| 235 |
tile_size=1024,
|
| 236 |
overlap=32
|
|
|
|
| 60 |
)
|
| 61 |
target_input_pixels = MAX_PIXEL_BUDGET / (upscale_factor ** 2)
|
| 62 |
scale = (target_input_pixels / (w * h)) ** 0.5
|
| 63 |
+
new_w = int(w * scale) // 16 * 16 # Ensure divisible by 16 for Flux compatibility
|
| 64 |
+
new_h = int(h * scale) // 16 * 16
|
| 65 |
+
if new_w == 0 or new_h == 0:
|
| 66 |
+
new_w = max(16, new_w)
|
| 67 |
+
new_h = max(16, new_h)
|
| 68 |
input_image = input_image.resize((new_w, new_h), resample=Image.LANCZOS)
|
| 69 |
was_resized = True
|
| 70 |
|
|
|
|
| 166 |
)
|
| 167 |
pipe.enable_vae_tiling()
|
| 168 |
pipe.enable_vae_slicing()
|
| 169 |
+
if device == "cuda":
|
| 170 |
+
pipe.enable_model_cpu_offload()
|
| 171 |
|
| 172 |
if USE_ESRGAN:
|
| 173 |
esrgan_path = "4x-UltraSharp.pth"
|
|
|
|
| 234 |
control_image,
|
| 235 |
denoising_strength,
|
| 236 |
num_inference_steps,
|
| 237 |
+
3.5, # Updated guidance_scale to match workflow (3.5)
|
| 238 |
generator,
|
| 239 |
tile_size=1024,
|
| 240 |
overlap=32
|