Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,17 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
|
|
|
| 4 |
clf = pipeline("text-classification", model="MayZhou/e5-small-lora-ai-generated-detector")
|
| 5 |
|
|
|
|
| 6 |
with gr.Blocks() as demo:
|
|
|
|
| 7 |
@gr.api()
|
| 8 |
-
def detect_ai(text: str)
|
| 9 |
try:
|
|
|
|
|
|
|
| 10 |
result = clf(text)[0]
|
| 11 |
label = result['label']
|
| 12 |
score = round(result['score'] * 100, 2)
|
|
@@ -14,4 +19,5 @@ with gr.Blocks() as demo:
|
|
| 14 |
except Exception as e:
|
| 15 |
return f"Error: {str(e)}"
|
| 16 |
|
|
|
|
| 17 |
demo.launch(show_api=True)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load the model outside the function
|
| 5 |
clf = pipeline("text-classification", model="MayZhou/e5-small-lora-ai-generated-detector")
|
| 6 |
|
| 7 |
+
# Define a Gradio Blocks app
|
| 8 |
with gr.Blocks() as demo:
|
| 9 |
+
|
| 10 |
@gr.api()
|
| 11 |
+
def detect_ai(text: str):
|
| 12 |
try:
|
| 13 |
+
if not text.strip():
|
| 14 |
+
return "Error: No text provided"
|
| 15 |
result = clf(text)[0]
|
| 16 |
label = result['label']
|
| 17 |
score = round(result['score'] * 100, 2)
|
|
|
|
| 19 |
except Exception as e:
|
| 20 |
return f"Error: {str(e)}"
|
| 21 |
|
| 22 |
+
# Important: show_api=True must be passed here
|
| 23 |
demo.launch(show_api=True)
|