Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +20 -56
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -1,77 +1,41 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
print("π Loading AI detection model...")
|
| 7 |
-
pipe = pipeline("text-classification", model="roberta-base-openai-detector")
|
| 8 |
-
print("β
Model loaded successfully!")
|
| 9 |
|
| 10 |
-
def detect_text(
|
| 11 |
-
|
| 12 |
-
if not text.strip():
|
| 13 |
return {}, "β Please enter some text."
|
| 14 |
|
| 15 |
try:
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
verdict =
|
| 23 |
-
|
| 24 |
-
# Make verdict more user-friendly
|
| 25 |
-
if verdict.upper() in ["LABEL_0", "FAKE", "AI"]:
|
| 26 |
-
verdict_message = "π€ This looks AI-generated"
|
| 27 |
-
elif verdict.upper() in ["LABEL_1", "REAL", "HUMAN"]:
|
| 28 |
-
verdict_message = "π This looks Human-written"
|
| 29 |
-
else:
|
| 30 |
-
verdict_message = f"β οΈ Unknown verdict: {verdict}"
|
| 31 |
-
|
| 32 |
-
return probs, verdict_message
|
| 33 |
-
|
| 34 |
except Exception as e:
|
| 35 |
return {}, f"β Error: {str(e)}"
|
| 36 |
|
| 37 |
-
|
| 38 |
with gr.Blocks() as demo:
|
| 39 |
-
gr.Markdown(
|
| 40 |
-
"""
|
| 41 |
-
# π΅οΈ AI Content Detector
|
| 42 |
-
Paste some text below and check if it's **AI-generated or Human-written**.
|
| 43 |
-
"""
|
| 44 |
-
)
|
| 45 |
|
| 46 |
with gr.Row():
|
| 47 |
-
text_input = gr.Textbox(
|
| 48 |
-
label="βοΈ Input Text",
|
| 49 |
-
lines=10,
|
| 50 |
-
placeholder="Paste text here..."
|
| 51 |
-
)
|
| 52 |
|
| 53 |
with gr.Row():
|
| 54 |
-
output_probs = gr.Label(label="
|
| 55 |
-
output_verdict = gr.Textbox(label="
|
| 56 |
|
| 57 |
with gr.Row():
|
| 58 |
-
submit_btn = gr.Button("
|
| 59 |
-
clear_btn = gr.Button("
|
| 60 |
-
|
| 61 |
-
# Submit action
|
| 62 |
-
submit_btn.click(
|
| 63 |
-
fn=detect_text,
|
| 64 |
-
inputs=text_input,
|
| 65 |
-
outputs=[output_probs, output_verdict],
|
| 66 |
-
)
|
| 67 |
|
| 68 |
-
|
| 69 |
-
clear_btn.click(
|
| 70 |
-
fn=lambda: ("", {}, ""),
|
| 71 |
-
inputs=[],
|
| 72 |
-
outputs=[text_input, output_probs, output_verdict],
|
| 73 |
-
)
|
| 74 |
|
| 75 |
-
# πΉ Launch app
|
| 76 |
if __name__ == "__main__":
|
| 77 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load state-of-the-art AI text detector
|
| 5 |
+
text_pipe = pipeline("text-classification", model="wangkevin02/AI_Detect_Model")
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
def detect_text(input_text: str):
|
| 8 |
+
if not input_text.strip():
|
|
|
|
| 9 |
return {}, "β Please enter some text."
|
| 10 |
|
| 11 |
try:
|
| 12 |
+
outputs = text_pipe(input_text)
|
| 13 |
+
# Outputs look like: [{'label':'0'/'1','score':...}]
|
| 14 |
+
label = outputs[0]["label"]
|
| 15 |
+
score = float(outputs[0]["score"])
|
| 16 |
+
|
| 17 |
+
prob = {"Human-written": 1 - score, "AI-generated": score}
|
| 18 |
+
verdict = "π€ This looks AI-generated" if label == "1" else "π This looks Human-written"
|
| 19 |
+
return prob, verdict
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
except Exception as e:
|
| 21 |
return {}, f"β Error: {str(e)}"
|
| 22 |
|
|
|
|
| 23 |
with gr.Blocks() as demo:
|
| 24 |
+
gr.Markdown("# AI Content Detector (Upgraded)\nFaster and more reliable detection using an advanced classifier.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
with gr.Row():
|
| 27 |
+
text_input = gr.Textbox(lines=10, placeholder="Paste text here...", label="Enter Text to Analyze")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
with gr.Row():
|
| 30 |
+
output_probs = gr.Label(label="Probabilities")
|
| 31 |
+
output_verdict = gr.Textbox(label="Verdict", interactive=False)
|
| 32 |
|
| 33 |
with gr.Row():
|
| 34 |
+
submit_btn = gr.Button("Check Text", variant="primary")
|
| 35 |
+
clear_btn = gr.Button("Clear")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
+
submit_btn.click(detect_text, inputs=text_input, outputs=[output_probs, output_verdict])
|
| 38 |
+
clear_btn.click(lambda: ("", {}, ""), inputs=[], outputs=[text_input, output_probs, output_verdict])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
|
|
|
| 40 |
if __name__ == "__main__":
|
| 41 |
demo.launch()
|
requirements.txt
CHANGED
|
@@ -3,3 +3,4 @@ transformers==4.43.3
|
|
| 3 |
torch>=2.0.0
|
| 4 |
accelerate>=0.33.0
|
| 5 |
safetensors>=0.4.2
|
|
|
|
|
|
| 3 |
torch>=2.0.0
|
| 4 |
accelerate>=0.33.0
|
| 5 |
safetensors>=0.4.2
|
| 6 |
+
pillow>=10.0.0
|