Spaces:
Running on Zero
Running on Zero
Download utils/validation.py from basyx/ai-gateway: direct link, hf CLI and curl.
- Browser
- Download file 680 Bytes
-
https://huggingface.co/spaces/basyx/ai-gateway/resolve/main/utils/validation.py
- Command line
-
hf download hf://spaces/basyx/ai-gateway/utils/validation.py
-
curl -L -o validation.py https://huggingface.co/spaces/basyx/ai-gateway/resolve/main/utils/validation.py
680 Bytes
| """Cross-field input validation.""" | |
| from core.errors import GatewayError | |
| def validate_image_dimensions(width: int, height: int, *, multiple: int = 8) -> None: | |
| """Require dimensions compatible with diffusion VAEs.""" | |
| if width % multiple or height % multiple: | |
| raise GatewayError( | |
| f"Image width and height must be multiples of {multiple}", | |
| code="invalid_dimensions", | |
| ) | |
| def validate_nonblank(value: str, field_name: str) -> str: | |
| """Reject strings containing only whitespace.""" | |
| cleaned = value.strip() | |
| if not cleaned: | |
| raise GatewayError(f"{field_name} cannot be blank", code="invalid_input") | |
| return cleaned | |