Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load the AI detection model pipeline from Hugging Face
|
5 |
+
# We're using a well-regarded RoBERTa-based model for this task.
|
6 |
+
pipe = pipeline("text-classification", model="michellejieli/roberta-base-openai-detector")
|
7 |
+
|
8 |
+
def detect_ai_text(text):
|
9 |
+
"""
|
10 |
+
Analyzes the input text and returns the model's prediction.
|
11 |
+
The model returns a list of dictionaries. We want the one that tells us the 'AI' score.
|
12 |
+
"""
|
13 |
+
results = pipe(text)
|
14 |
+
# The model outputs probabilities for both 'LABEL_0' (Human) and 'LABEL_1' (AI).
|
15 |
+
# We'll return the full results for clarity.
|
16 |
+
return {item['label']: item['score'] for item in results}
|
17 |
+
|
18 |
+
# Create the Gradio interface
|
19 |
+
iface = gr.Interface(
|
20 |
+
fn=detect_ai_text,
|
21 |
+
inputs=gr.Textbox(lines=10, placeholder="Paste the text you want to analyze here..."),
|
22 |
+
outputs="json",
|
23 |
+
title="AI Content Detector",
|
24 |
+
description="A simple API to detect AI-generated text. Powered by roberta-base-openai-detector."
|
25 |
+
)
|
26 |
+
|
27 |
+
# Launch the app. The `share=True` argument is what makes the API accessible.
|
28 |
+
iface.launch()
|