Spaces:
Sleeping
Sleeping
Commit ·
0d64f25
1
Parent(s): f95b090
Fix: Require heuristic evidence for AI verdict on non-English audio to prevent false positives
Browse files- app/infer.py +28 -6
app/infer.py
CHANGED
|
@@ -150,14 +150,37 @@ class VoiceClassifier:
|
|
| 150 |
# Apply penalty to the probability of being fake
|
| 151 |
prob_fake_adjusted = prob_fake * confidence_penalty
|
| 152 |
|
|
|
|
|
|
|
|
|
|
| 153 |
# 3. Final Decision
|
| 154 |
# We demand HIGHER evidence for AI (Conservatism)
|
| 155 |
-
threshold = 0.65 # Default threshold (requires >65% certainty)
|
| 156 |
|
| 157 |
-
#
|
| 158 |
-
|
| 159 |
-
threshold = 0.55
|
| 160 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
if prob_fake_adjusted > threshold:
|
| 162 |
prediction = "AI_GENERATED"
|
| 163 |
confidence = prob_fake_adjusted
|
|
@@ -165,8 +188,7 @@ class VoiceClassifier:
|
|
| 165 |
prediction = "HUMAN"
|
| 166 |
confidence = 1.0 - prob_fake_adjusted
|
| 167 |
|
| 168 |
-
# 4. Language Awareness Dampening
|
| 169 |
-
is_english = language.lower() in ["english", "en"]
|
| 170 |
if prediction == "AI_GENERATED" and not is_english:
|
| 171 |
confidence *= 0.9 # Extra caution for non-English
|
| 172 |
|
|
|
|
| 150 |
# Apply penalty to the probability of being fake
|
| 151 |
prob_fake_adjusted = prob_fake * confidence_penalty
|
| 152 |
|
| 153 |
+
# --- LANGUAGE AWARENESS ---
|
| 154 |
+
is_english = language.lower() in ["english", "en"]
|
| 155 |
+
|
| 156 |
# 3. Final Decision
|
| 157 |
# We demand HIGHER evidence for AI (Conservatism)
|
|
|
|
| 158 |
|
| 159 |
+
# Base threshold
|
| 160 |
+
threshold = 0.65
|
|
|
|
| 161 |
|
| 162 |
+
# Dynamic Thresholding based on Heuristics
|
| 163 |
+
if len(ai_flags) >= 2:
|
| 164 |
+
# Strong heuristic evidence (e.g. robotic pitch + flat spectrum)
|
| 165 |
+
# We lower the bar for the model
|
| 166 |
+
threshold = 0.50
|
| 167 |
+
elif len(ai_flags) == 1:
|
| 168 |
+
# Some heuristic evidence
|
| 169 |
+
threshold = 0.60
|
| 170 |
+
else:
|
| 171 |
+
# ZERO heuristic evidence (Pitch/Flatness look human)
|
| 172 |
+
# The model is alone in its accusation.
|
| 173 |
+
if not is_english:
|
| 174 |
+
# Foreign language + No Heuristics = FALSE POSITIVE likely.
|
| 175 |
+
# We force Human verdict unless we want to be extremely risky.
|
| 176 |
+
# Current decision: Force Human to protect against bias.
|
| 177 |
+
print("DEBUG: Non-English audio with NO heuristic AI flags. Forcing Human verdict.")
|
| 178 |
+
prob_fake_adjusted = 0.0
|
| 179 |
+
else:
|
| 180 |
+
# English + No Heuristics.
|
| 181 |
+
# Model must be overwhelmingly confident (>98%) to override heuristics.
|
| 182 |
+
threshold = 0.98
|
| 183 |
+
|
| 184 |
if prob_fake_adjusted > threshold:
|
| 185 |
prediction = "AI_GENERATED"
|
| 186 |
confidence = prob_fake_adjusted
|
|
|
|
| 188 |
prediction = "HUMAN"
|
| 189 |
confidence = 1.0 - prob_fake_adjusted
|
| 190 |
|
| 191 |
+
# 4. Language Awareness Dampening (for the resulting score)
|
|
|
|
| 192 |
if prediction == "AI_GENERATED" and not is_english:
|
| 193 |
confidence *= 0.9 # Extra caution for non-English
|
| 194 |
|