VictorM-Coder commited on
Commit
acb825e
·
verified ·
1 Parent(s): dc3e936

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -14
app.py CHANGED
@@ -3,20 +3,16 @@ from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
  import torch
4
  import re
5
 
6
- # Load model
7
- MODEL = "roberta-base-openai-detector"
8
  tokenizer = AutoTokenizer.from_pretrained(MODEL)
9
  model = AutoModelForSequenceClassification.from_pretrained(MODEL)
10
 
11
  def get_color(ai_score):
12
- """
13
- Convert AI score (0-1) into a smooth green-yellow-red gradient.
14
- """
15
  red = int(ai_score * 255)
16
  green = int((1 - ai_score) * 255)
17
  return f"rgb({red},{green},0)"
18
 
19
-
20
  def detect_ai(text):
21
  sentences = re.split(r'(?<=[.!?]) +', text)
22
  results = []
@@ -31,14 +27,11 @@ def detect_ai(text):
31
  ai_score = float(probs[0][1])
32
  results.append({"sentence": sent, "ai_score": ai_score})
33
 
34
- # Build highlighted HTML
35
  highlighted = ""
36
  for r in results:
37
  color = get_color(r['ai_score'])
38
- # Always mark as AI (show color regardless of how small)
39
  highlighted += f"<span style='background-color:{color}; padding:2px'>{r['sentence']} </span>"
40
 
41
- # Compute total AI percentage
42
  if results:
43
  avg_ai = sum(r['ai_score'] for r in results) / len(results)
44
  total_percent = round(avg_ai * 100, 2)
@@ -48,15 +41,13 @@ def detect_ai(text):
48
 
49
  return highlighted, {"sentences": results, "total_ai_percent": total_percent}
50
 
51
-
52
  with gr.Blocks() as demo:
53
- gr.Markdown("## 🤖 AI Detector (like ZeroGPT)")
54
- gr.Markdown("Paste your text below. Green = human-like, Yellow = mixed, Red = AI-like.")
55
- input_text = gr.Textbox(lines=8, placeholder="Enter text here...")
56
  output_html = gr.HTML()
57
  output_json = gr.JSON()
58
  run_btn = gr.Button("Detect AI")
59
-
60
  run_btn.click(detect_ai, inputs=input_text, outputs=[output_html, output_json])
61
 
62
  demo.launch()
 
3
  import torch
4
  import re
5
 
6
+ # Load more accurate detection model
7
+ MODEL = "desklib/ai-text-detector-v1.01"
8
  tokenizer = AutoTokenizer.from_pretrained(MODEL)
9
  model = AutoModelForSequenceClassification.from_pretrained(MODEL)
10
 
11
  def get_color(ai_score):
 
 
 
12
  red = int(ai_score * 255)
13
  green = int((1 - ai_score) * 255)
14
  return f"rgb({red},{green},0)"
15
 
 
16
  def detect_ai(text):
17
  sentences = re.split(r'(?<=[.!?]) +', text)
18
  results = []
 
27
  ai_score = float(probs[0][1])
28
  results.append({"sentence": sent, "ai_score": ai_score})
29
 
 
30
  highlighted = ""
31
  for r in results:
32
  color = get_color(r['ai_score'])
 
33
  highlighted += f"<span style='background-color:{color}; padding:2px'>{r['sentence']} </span>"
34
 
 
35
  if results:
36
  avg_ai = sum(r['ai_score'] for r in results) / len(results)
37
  total_percent = round(avg_ai * 100, 2)
 
41
 
42
  return highlighted, {"sentences": results, "total_ai_percent": total_percent}
43
 
 
44
  with gr.Blocks() as demo:
45
+ gr.Markdown("## AI Detector (upgraded to DeBERTa-v3 large)")
46
+ gr.Markdown("Paste text: green = human-like, yellow = mixed, red = AI-like.")
47
+ input_text = gr.Textbox(lines=8, placeholder="Enter text here")
48
  output_html = gr.HTML()
49
  output_json = gr.JSON()
50
  run_btn = gr.Button("Detect AI")
 
51
  run_btn.click(detect_ai, inputs=input_text, outputs=[output_html, output_json])
52
 
53
  demo.launch()