VictorM-Coder commited on
Commit
6400b6d
·
verified ·
1 Parent(s): 6c56aca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -4
app.py CHANGED
@@ -9,7 +9,6 @@ tokenizer = AutoTokenizer.from_pretrained(MODEL)
9
  model = AutoModelForSequenceClassification.from_pretrained(MODEL)
10
 
11
  def detect_ai(text):
12
- # Split into rough sentences
13
  sentences = re.split(r'(?<=[.!?]) +', text)
14
  results = []
15
 
@@ -20,17 +19,17 @@ def detect_ai(text):
20
  with torch.no_grad():
21
  outputs = model(**inputs)
22
  probs = torch.softmax(outputs.logits, dim=1)
23
- ai_score = float(probs[1])
24
  results.append({"sentence": sent, "ai_score": ai_score})
25
 
26
- # Build highlighted HTML
27
  highlighted = ""
28
  for r in results:
29
- color = f"rgba(255,0,0,{r['ai_score']})" # more red = more AI-like
30
  highlighted += f"<span style='background-color:{color}; padding:2px'>{r['sentence']} </span>"
31
 
32
  return highlighted, results
33
 
 
34
  with gr.Blocks() as demo:
35
  gr.Markdown("## 🤖 AI Detector (like ZeroGPT)")
36
  gr.Markdown("Paste your text below. Redder highlights = more AI-like.")
 
9
  model = AutoModelForSequenceClassification.from_pretrained(MODEL)
10
 
11
  def detect_ai(text):
 
12
  sentences = re.split(r'(?<=[.!?]) +', text)
13
  results = []
14
 
 
19
  with torch.no_grad():
20
  outputs = model(**inputs)
21
  probs = torch.softmax(outputs.logits, dim=1)
22
+ ai_score = float(probs[0][1]) # fix here
23
  results.append({"sentence": sent, "ai_score": ai_score})
24
 
 
25
  highlighted = ""
26
  for r in results:
27
+ color = f"rgba(255,0,0,{r['ai_score']})"
28
  highlighted += f"<span style='background-color:{color}; padding:2px'>{r['sentence']} </span>"
29
 
30
  return highlighted, results
31
 
32
+
33
  with gr.Blocks() as demo:
34
  gr.Markdown("## 🤖 AI Detector (like ZeroGPT)")
35
  gr.Markdown("Paste your text below. Redder highlights = more AI-like.")