import gradio as gr from ai_text_detector_valid_final import detect_text def analyze_text(user_text): return detect_text(user_text) with gr.Blocks(theme=gr.themes.Soft()) as demo: gr.Markdown( """ # 🤖 AI vs Human Text Detector Paste any text below. Our system will analyze it using **three advanced models** to detect if the text is AI-generated or human-written. ### 📝 Formatting Preservation - Your **line breaks, spacing, and Markdown syntax** will be preserved exactly as you paste them. - You can view it as **raw text** or **rendered Markdown**. - Perfect for analyzing **code snippets, poetry, or Markdown documents**. Click **"🚀 Run Detection"** to start. """ ) with gr.Row(): with gr.Column(scale=2): user_input = gr.Textbox( label="✍️ Enter Text", placeholder="Paste text here...", lines=12, type="text" ) analyze_btn = gr.Button("🚀 Run Detection", variant="primary") with gr.Column(scale=1): final_output = gr.JSON(label="📊 Final Results") with gr.Row(): with gr.Accordion("🔬 Detailed Model Results", open=False): model_output = gr.JSON(label="All Model Scores") # ✅ Two-tab preview: raw + markdown with gr.Tab("📄 Raw Text (Exact Preservation)"): raw_preview = gr.Textbox( label="📝 Raw Input", interactive=False, lines=20, show_copy_button=True ) with gr.Tab("✨ Rendered Markdown"): md_preview = gr.Markdown() def run_analysis(user_text): results = analyze_text(user_text) return results, results, user_text, user_text analyze_btn.click( fn=run_analysis, inputs=user_input, outputs=[final_output, model_output, raw_preview, md_preview] ) demo.launch()