Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,8 +3,8 @@ from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
|
| 3 |
import torch
|
| 4 |
import re
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
MODEL = "
|
| 8 |
tokenizer = AutoTokenizer.from_pretrained(MODEL)
|
| 9 |
model = AutoModelForSequenceClassification.from_pretrained(MODEL)
|
| 10 |
|
|
@@ -24,14 +24,18 @@ def detect_ai(text):
|
|
| 24 |
with torch.no_grad():
|
| 25 |
outputs = model(**inputs)
|
| 26 |
probs = torch.softmax(outputs.logits, dim=1)
|
|
|
|
|
|
|
| 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,9 +45,10 @@ def detect_ai(text):
|
|
| 41 |
|
| 42 |
return highlighted, {"sentences": results, "total_ai_percent": total_percent}
|
| 43 |
|
|
|
|
| 44 |
with gr.Blocks() as demo:
|
| 45 |
-
gr.Markdown("##
|
| 46 |
-
gr.Markdown("Paste text: green = human-like,
|
| 47 |
input_text = gr.Textbox(lines=8, placeholder="Enter text here…")
|
| 48 |
output_html = gr.HTML()
|
| 49 |
output_json = gr.JSON()
|
|
|
|
| 3 |
import torch
|
| 4 |
import re
|
| 5 |
|
| 6 |
+
# Stable AI detection model
|
| 7 |
+
MODEL = "Hello-SimpleAI/HC3-DeBERTa"
|
| 8 |
tokenizer = AutoTokenizer.from_pretrained(MODEL)
|
| 9 |
model = AutoModelForSequenceClassification.from_pretrained(MODEL)
|
| 10 |
|
|
|
|
| 24 |
with torch.no_grad():
|
| 25 |
outputs = model(**inputs)
|
| 26 |
probs = torch.softmax(outputs.logits, dim=1)
|
| 27 |
+
|
| 28 |
+
# HC3 model: [0] = human, [1] = ChatGPT
|
| 29 |
ai_score = float(probs[0][1])
|
| 30 |
results.append({"sentence": sent, "ai_score": ai_score})
|
| 31 |
|
| 32 |
+
# Highlight
|
| 33 |
highlighted = ""
|
| 34 |
for r in results:
|
| 35 |
color = get_color(r['ai_score'])
|
| 36 |
highlighted += f"<span style='background-color:{color}; padding:2px'>{r['sentence']} </span>"
|
| 37 |
|
| 38 |
+
# Total AI probability
|
| 39 |
if results:
|
| 40 |
avg_ai = sum(r['ai_score'] for r in results) / len(results)
|
| 41 |
total_percent = round(avg_ai * 100, 2)
|
|
|
|
| 45 |
|
| 46 |
return highlighted, {"sentences": results, "total_ai_percent": total_percent}
|
| 47 |
|
| 48 |
+
|
| 49 |
with gr.Blocks() as demo:
|
| 50 |
+
gr.Markdown("## 🤖 AI Detector (HC3 DeBERTa)")
|
| 51 |
+
gr.Markdown("Paste text: green = human-like, red = AI-like")
|
| 52 |
input_text = gr.Textbox(lines=8, placeholder="Enter text here…")
|
| 53 |
output_html = gr.HTML()
|
| 54 |
output_json = gr.JSON()
|