File size: 926 Bytes
513571d
5e2b57d
513571d
 
 
 
 
 
 
 
 
 
 
 
 
5e2b57d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
28
29
30
31
32
33
34
35
36
37

import gradio as gr
from transformers import pipeline

clf = pipeline("text-classification", model="MayZhou/e5-small-lora-ai-generated-detector")

@gr.api()  # 👈 this enables the /run/predict route!
def detect_ai(text: str):
    result = clf(text)[0]
    label = result['label']
    score = round(result['score'] * 100, 2)
    return f"{label} ({score}%)"

demo = gr.Interface(fn=detect_ai, inputs="textbox", outputs="text", title="AI Text Detector")
demo.launch()

# Load the model
clf = pipeline("text-classification", model="MayZhou/e5-small-lora-ai-generated-detector")

# Define detection function
def detect_ai(text):
    result = clf(text)[0]
    label = result['label']
    score = round(result['score'] * 100, 2)
    return f"{label} ({score}%)"

# Build the interface
demo = gr.Interface(
    fn=detect_ai,
    inputs="textbox",
    outputs="text",
    title="AI Text Detector"
)

# Launch the app
demo.launch()