Spaces:
Sleeping
Sleeping
| """ | |
| Shared epsilon-clamping utility. | |
| Validator requires scores strictly between 0 and 1: (0.001 … 0.999) | |
| """ | |
| EPSILON = 0.001 | |
| SCORE_MIN = EPSILON # 0.001 | |
| SCORE_MAX = 1.0 - EPSILON # 0.999 | |
| def clamp(score: float) -> float: | |
| """Clamp any score to (0.001, 0.999) — never exactly 0 or 1.""" | |
| try: | |
| v = float(score) | |
| except (TypeError, ValueError): | |
| return 0.5 # safe default for bad inputs | |
| if v != v: # NaN guard | |
| return 0.5 | |
| return max(SCORE_MIN, min(SCORE_MAX, v)) | |