Spaces:
Running
Running
update
#1
by mahigodike - opened
- inference.py +12 -7
inference.py
CHANGED
|
@@ -48,11 +48,14 @@ MAX_RETRIES = 2
|
|
| 48 |
# Global timeout safety (inference must complete in < 20 minutes)
|
| 49 |
MAX_RUNTIME_SECONDS = int(os.environ.get("MAX_RUNTIME_SECONDS", "1100")) # ~18.3 min
|
| 50 |
_start_time = time.time()
|
| 51 |
-
SCORE_EPSILON = 1e-
|
| 52 |
|
| 53 |
|
| 54 |
def to_open_interval_score(value: float) -> float:
|
| 55 |
-
"""Map scores to strict open interval (0, 1) for validator compliance.
|
|
|
|
|
|
|
|
|
|
| 56 |
try:
|
| 57 |
score = float(value)
|
| 58 |
except (TypeError, ValueError):
|
|
@@ -60,16 +63,18 @@ def to_open_interval_score(value: float) -> float:
|
|
| 60 |
|
| 61 |
if not math.isfinite(score):
|
| 62 |
score = 0.0
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
return 1.0 - SCORE_EPSILON
|
| 67 |
return score
|
| 68 |
|
| 69 |
|
| 70 |
def rounded_open_interval_score(value: float, ndigits: int = 4) -> float:
|
| 71 |
"""Round score for logs/reports while preserving strict (0, 1) bounds."""
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
|
| 75 |
class TeeStream:
|
|
|
|
| 48 |
# Global timeout safety (inference must complete in < 20 minutes)
|
| 49 |
MAX_RUNTIME_SECONDS = int(os.environ.get("MAX_RUNTIME_SECONDS", "1100")) # ~18.3 min
|
| 50 |
_start_time = time.time()
|
| 51 |
+
SCORE_EPSILON = 1e-3
|
| 52 |
|
| 53 |
|
| 54 |
def to_open_interval_score(value: float) -> float:
|
| 55 |
+
"""Map scores to strict open interval (0, 1) for validator compliance.
|
| 56 |
+
|
| 57 |
+
Guarantees the returned value satisfies 0 < value < 1.
|
| 58 |
+
"""
|
| 59 |
try:
|
| 60 |
score = float(value)
|
| 61 |
except (TypeError, ValueError):
|
|
|
|
| 63 |
|
| 64 |
if not math.isfinite(score):
|
| 65 |
score = 0.0
|
| 66 |
+
|
| 67 |
+
# Clamp into the safe open interval (SCORE_EPSILON, 1 - SCORE_EPSILON)
|
| 68 |
+
score = max(SCORE_EPSILON, min(1.0 - SCORE_EPSILON, score))
|
|
|
|
| 69 |
return score
|
| 70 |
|
| 71 |
|
| 72 |
def rounded_open_interval_score(value: float, ndigits: int = 4) -> float:
|
| 73 |
"""Round score for logs/reports while preserving strict (0, 1) bounds."""
|
| 74 |
+
clamped = to_open_interval_score(value)
|
| 75 |
+
rounded = round(clamped, ndigits)
|
| 76 |
+
# Re-clamp after rounding to guarantee strict (0, 1)
|
| 77 |
+
return to_open_interval_score(rounded)
|
| 78 |
|
| 79 |
|
| 80 |
class TeeStream:
|