Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,12 +3,16 @@ 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 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
demo.launch(show_api=True)
|
|
|
|
| 3 |
|
| 4 |
clf = pipeline("text-classification", model="MayZhou/e5-small-lora-ai-generated-detector")
|
| 5 |
|
| 6 |
+
# Create API function inside Blocks context
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
@gr.api()
|
| 9 |
+
def detect_ai(text: str) -> str:
|
| 10 |
+
try:
|
| 11 |
+
result = clf(text)[0]
|
| 12 |
+
label = result['label']
|
| 13 |
+
score = round(result['score'] * 100, 2)
|
| 14 |
+
return f"{label} ({score}%)"
|
| 15 |
+
except Exception as e:
|
| 16 |
+
return f"Error: {str(e)}"
|
| 17 |
|
| 18 |
+
demo.launch(server_name="0.0.0.0", show_api=True)
|