VictorM-Coder commited on
Commit
34ea950
·
verified ·
1 Parent(s): c1d0bb0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -25,8 +25,8 @@ def get_model():
25
  ).to(device).eval()
26
  return tokenizer, model
27
 
28
- # Threshold used ONLY for coloring (Red vs Green)
29
- THRESHOLD = 0.81
30
 
31
  # -----------------------------
32
  # UTILITIES
@@ -72,6 +72,7 @@ def analyze(text):
72
  return "—", "—", "<em>Please enter text...</em>", None
73
 
74
  word_count = len(text.split())
 
75
  if word_count < 300:
76
  warning_msg = f"⚠️ <b>Insufficient Text:</b> Your input has {word_count} words. Please enter at least 300 words for an accurate analysis."
77
  return "Too Short", "N/A", f"<div style='color: #b80d0d; padding: 20px; border: 1px solid #b80d0d; border-radius: 8px;'>{warning_msg}</div>", None
@@ -103,7 +104,7 @@ def analyze(text):
103
  weighted_avg = sum(p * l for p, l in zip(probs, lengths)) / total_words if total_words > 0 else 0
104
 
105
  # -----------------------------
106
- # HTML RECONSTRUCTION (Unfiltered Probabilities)
107
  # -----------------------------
108
  highlighted_html = "<div style='font-family: sans-serif; line-height: 1.8;'>"
109
  prob_map = {idx: probs[i] for i, idx in enumerate(pure_sents_indices)}
@@ -115,7 +116,7 @@ def analyze(text):
115
 
116
  if i in prob_map:
117
  score = prob_map[i]
118
- # Color is still determined by the 81% threshold for visual aid
119
  if score >= THRESHOLD:
120
  color, bg = "#b80d0d", "rgba(184, 13, 13, 0.15)" # RED
121
  else:
@@ -130,7 +131,6 @@ def analyze(text):
130
  highlighted_html += block
131
  highlighted_html += "</div>"
132
 
133
- # --- RAW RESULTS (No Masking) ---
134
  label = f"{weighted_avg:.1%} AI Probability"
135
  display_score = f"{weighted_avg:.2%}"
136
 
@@ -142,7 +142,7 @@ def analyze(text):
142
  # -----------------------------
143
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
144
  gr.Markdown("## 🕵️ AI Detector Pro: Raw Mode")
145
- gr.Markdown(f"Direct model output from **{MODEL_NAME}**. Visual highlight still triggers at **{THRESHOLD*100:.0f}%**.")
146
 
147
  with gr.Row():
148
  with gr.Column(scale=3):
 
25
  ).to(device).eval()
26
  return tokenizer, model
27
 
28
+ # UPDATED: Threshold changed from 0.81 to 0.59
29
+ THRESHOLD = 0.59
30
 
31
  # -----------------------------
32
  # UTILITIES
 
72
  return "—", "—", "<em>Please enter text...</em>", None
73
 
74
  word_count = len(text.split())
75
+ # Word count remains at 300
76
  if word_count < 300:
77
  warning_msg = f"⚠️ <b>Insufficient Text:</b> Your input has {word_count} words. Please enter at least 300 words for an accurate analysis."
78
  return "Too Short", "N/A", f"<div style='color: #b80d0d; padding: 20px; border: 1px solid #b80d0d; border-radius: 8px;'>{warning_msg}</div>", None
 
104
  weighted_avg = sum(p * l for p, l in zip(probs, lengths)) / total_words if total_words > 0 else 0
105
 
106
  # -----------------------------
107
+ # HTML RECONSTRUCTION
108
  # -----------------------------
109
  highlighted_html = "<div style='font-family: sans-serif; line-height: 1.8;'>"
110
  prob_map = {idx: probs[i] for i, idx in enumerate(pure_sents_indices)}
 
116
 
117
  if i in prob_map:
118
  score = prob_map[i]
119
+ # Logic now uses the 0.59 threshold
120
  if score >= THRESHOLD:
121
  color, bg = "#b80d0d", "rgba(184, 13, 13, 0.15)" # RED
122
  else:
 
131
  highlighted_html += block
132
  highlighted_html += "</div>"
133
 
 
134
  label = f"{weighted_avg:.1%} AI Probability"
135
  display_score = f"{weighted_avg:.2%}"
136
 
 
142
  # -----------------------------
143
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
144
  gr.Markdown("## 🕵️ AI Detector Pro: Raw Mode")
145
+ gr.Markdown(f"Direct model output from **{MODEL_NAME}**. Visual highlight now triggers at **{THRESHOLD*100:.0f}%**.")
146
 
147
  with gr.Row():
148
  with gr.Column(scale=3):