Spaces:
Runtime error
Runtime error
moose Claude Opus 4.7 (1M context) commited on
Commit ·
efe093f
1
Parent(s): b34fbef
Preserve input image aspect ratio when sliders are at default
Browse filesThe Qwen-Image-Edit pipeline defaults to 1024x1024 when given height=None
and width=None, which discards the input image's aspect ratio. When the
user hasn't touched the height/width sliders (both still at the slider
minimum of 256), read the dimensions from input image 1 and pass those
to the pipeline instead, snapped to the nearest multiple of 8 and
clamped to the slider's [256, 2048] range.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
app.py
CHANGED
|
@@ -217,8 +217,17 @@ def infer(
|
|
| 217 |
except Exception:
|
| 218 |
continue
|
| 219 |
|
| 220 |
-
|
| 221 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
print(f"Calling pipeline with prompt: '{prompt}'")
|
| 223 |
print(f"Negative Prompt: '{negative_prompt}'")
|
| 224 |
print(f"Seed: {seed}, Steps: {num_inference_steps}, Guidance: {true_guidance_scale}, Size: {width}x{height}")
|
|
|
|
| 217 |
except Exception:
|
| 218 |
continue
|
| 219 |
|
| 220 |
+
# If user left the sliders at their default minimum, derive output dimensions
|
| 221 |
+
# from input image 1 so the result preserves its aspect ratio. Round to the
|
| 222 |
+
# nearest multiple of 8 (the pipeline's required dimension step) and clamp
|
| 223 |
+
# to the slider's [256, 2048] range.
|
| 224 |
+
if height == 256 and width == 256:
|
| 225 |
+
if pil_images:
|
| 226 |
+
ref_w, ref_h = pil_images[0].size
|
| 227 |
+
width = max(256, min(2048, (ref_w // 8) * 8))
|
| 228 |
+
height = max(256, min(2048, (ref_h // 8) * 8))
|
| 229 |
+
else:
|
| 230 |
+
height, width = None, None
|
| 231 |
print(f"Calling pipeline with prompt: '{prompt}'")
|
| 232 |
print(f"Negative Prompt: '{negative_prompt}'")
|
| 233 |
print(f"Seed: {seed}, Steps: {num_inference_steps}, Guidance: {true_guidance_scale}, Size: {width}x{height}")
|