textdetectorai / app.py
djamker's picture
Update app.py
fc186ef verified
raw
history blame contribute delete
564 Bytes
import gradio as gr
from transformers import pipeline
clf = pipeline("text-classification", model="MayZhou/e5-small-lora-ai-generated-detector")
# Create API function inside Blocks context
with gr.Blocks() as demo:
@gr.api()
def detect_ai(text: str) -> str:
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)}"
demo.launch(server_name="0.0.0.0", show_api=True)