File size: 670 Bytes
beb040a
 
 
6e04b38
 
beb040a
28329d2
 
 
 
 
 
 
 
 
 
c973c9e
6e04b38
28329d2
 
 
 
6e04b38
28329d2
beb040a
28329d2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import gradio as gr
from transformers import pipeline

# Use a stable, supported model
clf = pipeline("text-classification", model="roberta-base-openai-detector")

def detect_ai(text):
    if not text.strip():
        return "No text provided."
    try:
        result = clf(text)[0]
        label = result['label']
        score = round(result['score'] * 100, 2)
        return f"{label} ({score}%)"
    except Exception as e:
        return f"Error: {str(e)}"

# Simple Interface to expose API at /api/predict/
demo = gr.Interface(
    fn=detect_ai,
    inputs=gr.Textbox(lines=4, label="Enter text"),
    outputs="text",
    title="AI Text Detector"
)

demo.launch()