Spaces:
Running
on
Zero
Running
on
Zero
File size: 3,305 Bytes
b0b4a53 abac7fb b0b4a53 abac7fb b0b4a53 abac7fb b0b4a53 5cc118f 0bbc111 5cc118f 0bbc111 5cc118f 0bbc111 5cc118f 0bbc111 5cc118f 0bbc111 5cc118f 0bbc111 5cc118f 0bbc111 5cc118f 0bbc111 5cc118f 0bbc111 5cc118f 0bbc111 5cc118f 0bbc111 5cc118f 0bbc111 5cc118f 0bbc111 5cc118f 0bbc111 5cc118f 0bbc111 b0b4a53 0bbc111 b0b4a53 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
import gradio as gr
from detector import CustomDetector
# Initialize the detector
detector = CustomDetector()
def detect_text(text):
"""
Compute the AI-generated text score for the input text.
Returns a string with the score and classification (AI-generated or human-generated).
"""
if not text.strip():
return "Please enter some text."
score = detector.compute_score(text)
classification = "AI-generated" if score > 0.2 else "human-generated"
interpretation = (
f"Score: {score:.4f}\n"
f"Classification: {classification}\n"
"Note: Scores above 0.2 indicate AI-generated text; scores below 0.2 indicate human-generated text."
)
return interpretation
# Simplified CSS for a clean, modern look without cursor
custom_css = """
/* General styling for a minimalist, clean aesthetic */
body {
font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
color: #1a1a1a;
line-height: 1.6;
}
/* Center the Gradio container with flexible width */
.gradio-container {
max-width: 90%;
width: 800px;
margin: 2rem auto;
padding: 2rem;
background: rgba(255, 255, 255, 0.95);
border-radius: 12px;
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}
/* Title styling */
h1 {
font-size: 2.2rem;
font-weight: 700;
text-align: center;
color: #2c3e50;
margin-bottom: 1.5rem;
}
/* Input textbox */
textarea {
border: 2px solid #e0e0e0 !important;
border-radius: 8px !important;
padding: 1rem !important;
font-size: 1rem !important;
transition: border-color 0.3s ease !important;
}
textarea:focus {
border-color: #6c5ce7 !important;
box-shadow: 0 0 6px rgba(108, 92, 231, 0.2) !important;
}
/* Output textbox */
.output-text {
background: #f8f9fa !important;
border-radius: 8px !important;
padding: 1.5rem !important;
font-size: 1rem !important;
color: #2d3436 !important;
border: 1px solid #dfe6e9 !important;
}
/* Button styling with subtle hover effect */
button {
background: #6c5ce7 !important;
color: white !important;
border: none !important;
padding: 0.75rem 1.5rem !important;
border-radius: 8px !important;
font-weight: 600 !important;
transition: background 0.2s ease !important;
}
button:hover {
background: #5a4bc7 !important;
}
/* Ensure content stays within viewport */
html, body {
overflow-x: visible;
overflow-y: auto;
}
/* Responsive design */
@media (max-width: 600px) {
.gradio-container {
margin: 1rem;
padding: 1rem;
width: 95%;
}
h1 {
font-size: 1.8rem;
}
}
"""
# Set up the Gradio interface
iface = gr.Interface(
fn=detect_text,
inputs=gr.Textbox(
lines=5,
placeholder="Enter text here to check if it's AI-generated...",
label="Input Text"
),
outputs=gr.Textbox(label="Detection Result"),
title="AI-Generated Text Detector",
description="Enter text to detect if it was generated by an AI model. Powered by a custom detector using tiiuae/falcon-rw-1b.",
css=custom_css,
theme=None # Disable default theme to use custom CSS
)
# Launch the app
if __name__ == "__main__":
iface.launch() |