yagnik12 commited on
Commit
ea16ad3
·
verified ·
1 Parent(s): 00fea7d

Update ai_text_detector_valid_final.py

Browse files
Files changed (1) hide show
  1. ai_text_detector_valid_final.py +22 -9
ai_text_detector_valid_final.py CHANGED
@@ -102,6 +102,20 @@ def run_hf_model(model_id, text):
102
  # ---------------------------
103
  # Main Detector
104
  # ---------------------------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
  def detect_text(text):
106
  results = {}
107
  # HuggingFace transformer models
@@ -112,7 +126,7 @@ def detect_text(text):
112
  results["SzegedAI Detector"] = classify_szegedai(text)
113
 
114
  # ---------------------------
115
- # Improved Final Verdict
116
  # ---------------------------
117
  ai_probs = []
118
  strong_ai_detector = None
@@ -126,17 +140,16 @@ def detect_text(text):
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__":
 
102
  # ---------------------------
103
  # Main Detector
104
  # ---------------------------
105
+ def verdict(ai_prob):
106
+ """Return a human-readable verdict based on AI probability"""
107
+ if ai_prob < 20:
108
+ return "Most likely human-written."
109
+ elif 20 <= ai_prob < 40:
110
+ return "Possibly human-written with minimal AI assistance."
111
+ elif 40 <= ai_prob < 60:
112
+ return "Unclear – could be either human or AI-assisted."
113
+ elif 60 <= ai_prob < 80:
114
+ return "Possibly AI-generated, or a human using AI assistance."
115
+ else: # ai_prob >= 80
116
+ return "Likely AI-generated or heavily AI-assisted."
117
+
118
+
119
  def detect_text(text):
120
  results = {}
121
  # HuggingFace transformer models
 
126
  results["SzegedAI Detector"] = classify_szegedai(text)
127
 
128
  # ---------------------------
129
+ # Final Verdict (Hybrid Rule)
130
  # ---------------------------
131
  ai_probs = []
132
  strong_ai_detector = None
 
140
  avg_ai = np.mean(ai_probs) if ai_probs else 0
141
 
142
  if strong_ai_detector:
143
+ final_verdict = verdict(strong_ai_detector["AI Probability"])
144
  if "Identified LLM" in strong_ai_detector:
145
+ final_verdict += f" (Identified: {strong_ai_detector['Identified LLM']})"
 
 
 
 
146
  else:
147
+ final_verdict = verdict(avg_ai)
148
 
149
+ results["Final Score"] = {
150
+ "Verdict": final_verdict,
151
+ "Average AI Probability": round(avg_ai, 2)
152
+ }
153
  return results
154
 
155
  if __name__ == "__main__":