Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,15 @@ MODEL = "roberta-base-openai-detector"
|
|
| 8 |
tokenizer = AutoTokenizer.from_pretrained(MODEL)
|
| 9 |
model = AutoModelForSequenceClassification.from_pretrained(MODEL)
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
def detect_ai(text):
|
| 12 |
sentences = re.split(r'(?<=[.!?]) +', text)
|
| 13 |
results = []
|
|
@@ -25,7 +34,8 @@ def detect_ai(text):
|
|
| 25 |
# Build highlighted HTML
|
| 26 |
highlighted = ""
|
| 27 |
for r in results:
|
| 28 |
-
color =
|
|
|
|
| 29 |
highlighted += f"<span style='background-color:{color}; padding:2px'>{r['sentence']} </span>"
|
| 30 |
|
| 31 |
# Compute total AI percentage
|
|
@@ -39,10 +49,9 @@ def detect_ai(text):
|
|
| 39 |
return highlighted, {"sentences": results, "total_ai_percent": total_percent}
|
| 40 |
|
| 41 |
|
| 42 |
-
|
| 43 |
with gr.Blocks() as demo:
|
| 44 |
gr.Markdown("## 🤖 AI Detector (like ZeroGPT)")
|
| 45 |
-
gr.Markdown("Paste your text below.
|
| 46 |
input_text = gr.Textbox(lines=8, placeholder="Enter text here...")
|
| 47 |
output_html = gr.HTML()
|
| 48 |
output_json = gr.JSON()
|
|
|
|
| 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 = []
|
|
|
|
| 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
|
|
|
|
| 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()
|