Spaces:
Sleeping
Sleeping
Shreya Pal commited on
Commit ·
a44e3ea
1
Parent(s): 7dca781
Adjust moderation thresholds for stricter tiering
Browse files- server/app.py +18 -6
server/app.py
CHANGED
|
@@ -118,18 +118,30 @@ def score_based_moderate(text: str, hf_scores: dict) -> dict:
|
|
| 118 |
|
| 119 |
top = max(toxicity, threat, insult, obscene, severe, identity)
|
| 120 |
|
| 121 |
-
|
|
|
|
| 122 |
return {"decision": "remove", "confidence": round(min(0.95, top + 0.1), 2),
|
| 123 |
"explanation": "Content contains severe toxicity, a credible threat, or targeted hate speech."}
|
| 124 |
-
|
|
|
|
|
|
|
| 125 |
return {"decision": "remove", "confidence": round(top, 2),
|
| 126 |
-
"explanation": "
|
| 127 |
-
|
|
|
|
|
|
|
| 128 |
return {"decision": "flag", "confidence": round(top, 2),
|
| 129 |
-
"explanation": "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
else:
|
| 131 |
return {"decision": "allow", "confidence": round(1.0 - top, 2),
|
| 132 |
-
"explanation": "Content appears safe with low toxicity scores
|
| 133 |
|
| 134 |
@app.post("/moderate")
|
| 135 |
def moderate(request: ModerationRequest):
|
|
|
|
| 118 |
|
| 119 |
top = max(toxicity, threat, insult, obscene, severe, identity)
|
| 120 |
|
| 121 |
+
# REMOVE: only genuinely harmful content
|
| 122 |
+
if severe > 0.4 or threat > 0.7 or (toxicity > 0.85 and identity > 0.5):
|
| 123 |
return {"decision": "remove", "confidence": round(min(0.95, top + 0.1), 2),
|
| 124 |
"explanation": "Content contains severe toxicity, a credible threat, or targeted hate speech."}
|
| 125 |
+
|
| 126 |
+
# REMOVE: very high combined scores
|
| 127 |
+
elif toxicity > 0.85 and insult > 0.85:
|
| 128 |
return {"decision": "remove", "confidence": round(top, 2),
|
| 129 |
+
"explanation": "Highly toxic and insulting content that violates community guidelines."}
|
| 130 |
+
|
| 131 |
+
# FLAG: mildly toxic or insulting — needs human review
|
| 132 |
+
elif toxicity > 0.6 or insult > 0.7 or top > 0.6:
|
| 133 |
return {"decision": "flag", "confidence": round(top, 2),
|
| 134 |
+
"explanation": "Mildly toxic or insulting content. Flagged for human review."}
|
| 135 |
+
|
| 136 |
+
# FLAG: borderline
|
| 137 |
+
elif top > 0.4:
|
| 138 |
+
return {"decision": "flag", "confidence": round(top, 2),
|
| 139 |
+
"explanation": "Potentially offensive content detected. Flagged for review."}
|
| 140 |
+
|
| 141 |
+
# ALLOW: safe
|
| 142 |
else:
|
| 143 |
return {"decision": "allow", "confidence": round(1.0 - top, 2),
|
| 144 |
+
"explanation": "Content appears safe with low toxicity scores."}
|
| 145 |
|
| 146 |
@app.post("/moderate")
|
| 147 |
def moderate(request: ModerationRequest):
|