Spaces:
Sleeping
Sleeping
Update app.py.txt
Browse files- app.py.txt +17 -23
app.py.txt
CHANGED
@@ -1,23 +1,17 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
def detect_ai(text):
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
outputs="text",
|
19 |
-
title="AI Text Detector"
|
20 |
-
)
|
21 |
-
|
22 |
-
# Launch the app
|
23 |
-
demo.launch()
|
|
|
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) -> str:
|
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 |
+
demo.launch(show_api=True)
|
|
|
|
|
|
|
|
|
|
|
|