Spaces:
Running
Running
Update ai_text_detector_valid_final.py
Browse files
ai_text_detector_valid_final.py
CHANGED
|
@@ -111,19 +111,32 @@ def detect_text(text):
|
|
| 111 |
# SzegedAI ModernBERT ensemble
|
| 112 |
results["SzegedAI Detector"] = classify_szegedai(text)
|
| 113 |
|
| 114 |
-
#
|
|
|
|
|
|
|
| 115 |
ai_probs = []
|
| 116 |
-
|
|
|
|
|
|
|
| 117 |
if "AI Probability" in v:
|
| 118 |
ai_probs.append(v["AI Probability"])
|
|
|
|
|
|
|
|
|
|
| 119 |
avg_ai = np.mean(ai_probs) if ai_probs else 0
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
else:
|
| 125 |
verdict = "Likely human-written"
|
| 126 |
-
|
|
|
|
| 127 |
return results
|
| 128 |
|
| 129 |
if __name__ == "__main__":
|
|
|
|
| 111 |
# SzegedAI ModernBERT ensemble
|
| 112 |
results["SzegedAI Detector"] = classify_szegedai(text)
|
| 113 |
|
| 114 |
+
# ---------------------------
|
| 115 |
+
# Improved Final Verdict
|
| 116 |
+
# ---------------------------
|
| 117 |
ai_probs = []
|
| 118 |
+
strong_ai_detector = None
|
| 119 |
+
|
| 120 |
+
for k, v in results.items():
|
| 121 |
if "AI Probability" in v:
|
| 122 |
ai_probs.append(v["AI Probability"])
|
| 123 |
+
if v["AI Probability"] > 90: # strong AI flag
|
| 124 |
+
strong_ai_detector = v
|
| 125 |
+
|
| 126 |
avg_ai = np.mean(ai_probs) if ai_probs else 0
|
| 127 |
+
|
| 128 |
+
if strong_ai_detector:
|
| 129 |
+
verdict = f"Likely AI-generated"
|
| 130 |
+
if "Identified LLM" in strong_ai_detector:
|
| 131 |
+
verdict += f" (Identified: {strong_ai_detector['Identified LLM']})"
|
| 132 |
+
elif avg_ai > 60:
|
| 133 |
+
verdict = "Possibly AI-generated (with assistance)"
|
| 134 |
+
elif 40 <= avg_ai <= 60:
|
| 135 |
+
verdict = "Uncertain / Mixed signals"
|
| 136 |
else:
|
| 137 |
verdict = "Likely human-written"
|
| 138 |
+
|
| 139 |
+
results["Final Score"] = {"Verdict": verdict, "Average AI Probability": round(avg_ai, 2)}
|
| 140 |
return results
|
| 141 |
|
| 142 |
if __name__ == "__main__":
|