Spaces:
Sleeping
Sleeping
Commit ·
70820b4
1
Parent(s): 69e411d
Add NaN/Inf safety check to prevent JSON serialization errors
Browse files
src/components/model_wrapper.py
CHANGED
|
@@ -94,4 +94,10 @@ class ModelWrapper:
|
|
| 94 |
# Typically, LABEL_1 is the positive class (spoof).
|
| 95 |
|
| 96 |
ai_prob = probs[0][1].item()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
return ai_prob
|
|
|
|
| 94 |
# Typically, LABEL_1 is the positive class (spoof).
|
| 95 |
|
| 96 |
ai_prob = probs[0][1].item()
|
| 97 |
+
|
| 98 |
+
# Safety check: handle NaN/Inf (can occur if model weights are improperly loaded)
|
| 99 |
+
if not torch.isfinite(torch.tensor(ai_prob)):
|
| 100 |
+
print(f"WARNING: Model returned non-finite value: {ai_prob}. Returning 0.5 as fallback.")
|
| 101 |
+
return 0.5
|
| 102 |
+
|
| 103 |
return ai_prob
|