yagnik12's picture
Update app.py
97cd450 verified
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()