Spaces:
Running on Zero
Running on Zero
| from __future__ import annotations | |
| import math | |
| from dataclasses import dataclass | |
| def sigmoid(value: float) -> float: | |
| if value >= 0: | |
| z = math.exp(-value) | |
| return 1.0 / (1.0 + z) | |
| z = math.exp(value) | |
| return z / (1.0 + z) | |
| def clamp_probability(value: float) -> float: | |
| if not math.isfinite(value): | |
| raise ValueError("probability must be finite") | |
| return max(0.0, min(1.0, value)) | |
| class ModelResult: | |
| detector_key: str | |
| model_version: str | |
| ai_probability: float | |
| raw_score: float | |
| latency_ms: int | |
| input_size: int | |
| def as_dict(self) -> dict[str, object]: | |
| return { | |
| "detector_key": self.detector_key, | |
| "model_version": self.model_version, | |
| "ai_probability": clamp_probability(self.ai_probability), | |
| "raw_score": self.raw_score, | |
| "latency_ms": self.latency_ms, | |
| "input_size": self.input_size, | |
| } | |