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

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

# Define a Gradio Blocks app
with gr.Blocks() as demo:

    @gr.api()
    def detect_ai(text: str):
        try:
            if not text.strip():
                return "Error: No text provided"
            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)}"

# Important: show_api=True must be passed here
demo.launch(show_api=True)