Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,23 +1,25 @@
|
|
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 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
score = round(result['score'] * 100, 2)
|
18 |
-
return f"{label} ({score}%)"
|
19 |
-
except Exception as e:
|
20 |
-
return f"Error: {str(e)}"
|
21 |
|
22 |
-
|
23 |
-
demo.launch(show_api=True)
|
|
|
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 |
+
def detect_ai(text):
|
7 |
+
if not text.strip():
|
8 |
+
return "No text provided."
|
9 |
+
try:
|
10 |
+
result = clf(text)[0]
|
11 |
+
label = result['label']
|
12 |
+
score = round(result['score'] * 100, 2)
|
13 |
+
return f"{label} ({score}%)"
|
14 |
+
except Exception as e:
|
15 |
+
return f"Error: {str(e)}"
|
16 |
|
17 |
+
# Launch the app with a basic Gradio Interface (exposes /predict endpoint)
|
18 |
+
demo = gr.Interface(
|
19 |
+
fn=detect_ai,
|
20 |
+
inputs=gr.Textbox(lines=4, label="Enter text"),
|
21 |
+
outputs="text",
|
22 |
+
title="AI Text Detector",
|
23 |
+
)
|
|
|
|
|
|
|
|
|
24 |
|
25 |
+
demo.launch()
|
|