Spaces:
Configuration error
Configuration error
Download axis_numeric/form_fields.py from serety95/axis-numeric: direct link, hf CLI and curl.
- Browser
- Download file 1.47 kB
-
https://huggingface.co/spaces/serety95/axis-numeric/resolve/main/axis_numeric/form_fields.py
- Command line
-
hf download hf://spaces/serety95/axis-numeric/axis_numeric/form_fields.py
-
curl -L -o form_fields.py https://huggingface.co/spaces/serety95/axis-numeric/resolve/main/axis_numeric/form_fields.py
1.47 kB
| """@module numeric-inference/form-fields — index-aligned optional multipart fields.""" | |
| def optional_lengths(values: list[str] | None, count: int) -> list[int | None]: | |
| """One length per file. Blank means unconstrained. A short list is rejected.""" | |
| if values is None: | |
| return [None] * count | |
| if len(values) != count: | |
| raise ValueError("invalid_numeric_request") | |
| parsed: list[int | None] = [] | |
| for item in values: | |
| text = item.strip() | |
| if not text: | |
| parsed.append(None) | |
| continue | |
| if not text.isdigit(): | |
| raise ValueError("invalid_numeric_request") | |
| number = int(text) | |
| if not 1 <= number <= 64: | |
| raise ValueError("invalid_numeric_request") | |
| parsed.append(number) | |
| return parsed | |
| def optional_flags(values: list[str] | None, count: int) -> list[bool]: | |
| """One agreement flag per file. Omitted or blank means that crop is unconfirmed.""" | |
| if values is None: | |
| return [False] * count | |
| if len(values) != count: | |
| raise ValueError("invalid_numeric_request") | |
| parsed: list[bool] = [] | |
| for item in values: | |
| text = item.strip().lower() | |
| if text in {"", "0", "false", "no"}: | |
| parsed.append(False) | |
| elif text in {"1", "true", "yes"}: | |
| parsed.append(True) | |
| else: | |
| raise ValueError("invalid_numeric_request") | |
| return parsed | |