Spaces:
Running
on
Zero
Running
on
Zero
| 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() |