Spaces:
Running on Zero
fix(fit): restore gradio arg alignment + stop masking wiring errors as payload_too_long
Browse files- 61aae8d inserted link_lifetime mid-signature; gradio passes UI values
positionally, shifting every arg after use_temporary_short_link by one:
image_size got border (4px), error_correction got module_size int, so the
EC-label dict KeyError'd and _safe_compute masked it as overflow β a 100%
payload_too_long wall on the space UI since 2026-08-04.
- Move link_lifetime to keyword-only in generate_standard_qr and
generate_artistic_qr; gradio's 26/43 positional inputs align again.
Modal/gateway path (build_generation_kwargs, by-name) unaffected.
- qr_fit._safe_compute now converts only true capacity overflows
(DataOverflowError / qrcode 'Invalid version' ValueError) to None; anything
else is logged and re-raised so broken wiring surfaces as the real error
instead of a fake payload_too_long.
|
@@ -2993,7 +2993,6 @@ def generate_standard_qr(
|
|
| 2993 |
text_input: str = "",
|
| 2994 |
input_type: str = "URL",
|
| 2995 |
use_temporary_short_link: bool = False,
|
| 2996 |
-
link_lifetime: str | None = None,
|
| 2997 |
image_size: int = 512,
|
| 2998 |
border_size: int = 4,
|
| 2999 |
error_correction: str = "Medium (15%)",
|
|
@@ -3015,6 +3014,8 @@ def generate_standard_qr(
|
|
| 3015 |
gradient_strength: float = 0.3,
|
| 3016 |
variation_steps: int = 5,
|
| 3017 |
analytics_opt_in: bool = False,
|
|
|
|
|
|
|
| 3018 |
progress=gr.Progress(),
|
| 3019 |
request: Union[gr.Request, None] = None,
|
| 3020 |
):
|
|
@@ -3304,7 +3305,6 @@ def generate_artistic_qr(
|
|
| 3304 |
text_input: str = "",
|
| 3305 |
input_type: str = "URL",
|
| 3306 |
use_temporary_short_link: bool = False,
|
| 3307 |
-
link_lifetime: str | None = None,
|
| 3308 |
image_size: int = 512,
|
| 3309 |
border_size: int = 4,
|
| 3310 |
error_correction: str = "Medium (15%)",
|
|
@@ -3343,6 +3343,8 @@ def generate_artistic_qr(
|
|
| 3343 |
gradient_strength: float = 0.3,
|
| 3344 |
variation_steps: int = 5,
|
| 3345 |
analytics_opt_in: bool = False,
|
|
|
|
|
|
|
| 3346 |
progress=gr.Progress(),
|
| 3347 |
request: Union[gr.Request, None] = None,
|
| 3348 |
):
|
|
|
|
| 2993 |
text_input: str = "",
|
| 2994 |
input_type: str = "URL",
|
| 2995 |
use_temporary_short_link: bool = False,
|
|
|
|
| 2996 |
image_size: int = 512,
|
| 2997 |
border_size: int = 4,
|
| 2998 |
error_correction: str = "Medium (15%)",
|
|
|
|
| 3014 |
gradient_strength: float = 0.3,
|
| 3015 |
variation_steps: int = 5,
|
| 3016 |
analytics_opt_in: bool = False,
|
| 3017 |
+
*,
|
| 3018 |
+
link_lifetime: str | None = None,
|
| 3019 |
progress=gr.Progress(),
|
| 3020 |
request: Union[gr.Request, None] = None,
|
| 3021 |
):
|
|
|
|
| 3305 |
text_input: str = "",
|
| 3306 |
input_type: str = "URL",
|
| 3307 |
use_temporary_short_link: bool = False,
|
|
|
|
| 3308 |
image_size: int = 512,
|
| 3309 |
border_size: int = 4,
|
| 3310 |
error_correction: str = "Medium (15%)",
|
|
|
|
| 3343 |
gradient_strength: float = 0.3,
|
| 3344 |
variation_steps: int = 5,
|
| 3345 |
analytics_opt_in: bool = False,
|
| 3346 |
+
*,
|
| 3347 |
+
link_lifetime: str | None = None,
|
| 3348 |
progress=gr.Progress(),
|
| 3349 |
request: Union[gr.Request, None] = None,
|
| 3350 |
):
|
|
@@ -15,6 +15,8 @@ redundancy) β and only then raise a structured payload_too_long error.
|
|
| 15 |
must return the QR pixel size for those settings (matrix modules Γ module size).
|
| 16 |
"""
|
| 17 |
|
|
|
|
|
|
|
| 18 |
PAYLOAD_TOO_LONG_ERROR_CLASS = "payload_too_long"
|
| 19 |
|
| 20 |
_EC_NOTCH_DOWN = {
|
|
@@ -69,11 +71,27 @@ def auto_fit_qr_dimensions(
|
|
| 69 |
|
| 70 |
def _safe_compute(b: int, e: str, m: int) -> int | None:
|
| 71 |
"""Pixel size for these settings, or None if the payload exceeds QR
|
| 72 |
-
capacity at this error-correction level (matrix can't be built).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
try:
|
| 74 |
return compute(border_size=b, error_correction=e, module_size=m)
|
| 75 |
-
except Exception:
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
# Fast path: fits as requested β byte-identical settings, no adjustment.
|
| 79 |
required = _safe_compute(border, ec, mod)
|
|
|
|
| 15 |
must return the QR pixel size for those settings (matrix modules Γ module size).
|
| 16 |
"""
|
| 17 |
|
| 18 |
+
import traceback
|
| 19 |
+
|
| 20 |
PAYLOAD_TOO_LONG_ERROR_CLASS = "payload_too_long"
|
| 21 |
|
| 22 |
_EC_NOTCH_DOWN = {
|
|
|
|
| 71 |
|
| 72 |
def _safe_compute(b: int, e: str, m: int) -> int | None:
|
| 73 |
"""Pixel size for these settings, or None if the payload exceeds QR
|
| 74 |
+
capacity at this error-correction level (matrix can't be built).
|
| 75 |
+
|
| 76 |
+
Only a true capacity overflow is converted to None: qrcode's
|
| 77 |
+
DataOverflowError, or the ValueError("Invalid version ...") that
|
| 78 |
+
qrcode 7.x/8.x raise from make(fit=True) when the payload needs a
|
| 79 |
+
version beyond 40 (both matched by name/message to keep this module
|
| 80 |
+
dependency-free). Any other exception means broken caller wiring (bad
|
| 81 |
+
label, shifted args, type error) β log it loudly and re-raise so it
|
| 82 |
+
surfaces as the real error instead of a misleading payload_too_long
|
| 83 |
+
wall."""
|
| 84 |
try:
|
| 85 |
return compute(border_size=b, error_correction=e, module_size=m)
|
| 86 |
+
except Exception as exc:
|
| 87 |
+
is_capacity = type(exc).__name__ == "DataOverflowError" or (
|
| 88 |
+
isinstance(exc, ValueError) and "Invalid version" in str(exc)
|
| 89 |
+
)
|
| 90 |
+
if is_capacity:
|
| 91 |
+
return None
|
| 92 |
+
print("[qr_fit] compute raised a NON-capacity error β re-raising:")
|
| 93 |
+
traceback.print_exc()
|
| 94 |
+
raise
|
| 95 |
|
| 96 |
# Fast path: fits as requested β byte-identical settings, no adjustment.
|
| 97 |
required = _safe_compute(border, ec, mod)
|