Spaces:
Build error
Build error
Update app.py
Browse files1234457867891011121314151610111213141516171819201718192021222324222325import gradio as grfrom transformers import pipeline
# Load the model outside the functionclf = pipeline("text-classification", model="MayZhou/e5-small-lora-ai-generated-detector")
# Define a Gradio Blocks appwith gr.Blocks() as demo: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)}"
@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)}"# Launch the app with a basic Gradio Interface (exposes /predict endpoint)demo = gr.Interface( fn=detect_ai, inputs=gr.Textbox(lines=4, label="Enter text"), outputs="text", title="AI Text Detector",)
# Important: show_api=True must be passed heredemo.launch(show_api=True)demo.launch()app.py+18-16