import torch import gradio as gr from transformers import ( AutoTokenizer, AutoModelForSequenceClassification ) # ========================= # Model loading (UNCHANGED) # ========================= MODEL_NAME = "duclo90/results" tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME) model = AutoModelForSequenceClassification.from_pretrained(MODEL_NAME) model.eval() # ========================= # Inference logic (UNCHANGED) # ========================= def classify_text(text): if not text.strip(): return """

⚠️ Oops!

Please enter some text to analyze

""" inputs = tokenizer( text, return_tensors="pt", truncation=True, max_length=512 ) with torch.no_grad(): outputs = model(**inputs) probs = torch.softmax(outputs.logits, dim=-1) score, pred = torch.max(probs, dim=-1) label = model.config.id2label[pred.item()] if label.lower() == "human": return """
👤

Human-Written

This text appears to be written by a human

✨ Natural & Authentic
""" else: return """
🤖

AI-Generated

This text appears to be machine-generated

⚡ AI-Powered Content
""" # ========================= # CSS (ONLY UI REMOVALS) # ========================= custom_css = """ /* Remove Gradio top bar, API button, settings, footer */ header, footer, .gradio-header, .gradio-footer, .gradio-toolbar, #top-bar, [class*="header"], [class*="toolbar"], [class*="footer"], .svelte-1ipelgc, .svelte-1xw6x5s { display: none !important; height: 0 !important; min-height: 0 !important; visibility: hidden !important; padding: 0 !important; margin: 0 !important; } /* Remove leftover spacing */ body { margin: 0 !important; padding: 0 !important; } /* Your existing styles */ #component-0 { max-width: 900px; margin: auto; padding: 20px; } .gradio-container { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important; font-family: 'Inter', sans-serif; min-height: 100vh !important; } #title { text-align: center; color: white; font-size: 2.5em; font-weight: 700; margin-bottom: 10px; } #description { text-align: center; color: rgba(255,255,255,0.9); font-size: 1.1em; margin-bottom: 30px; } .input-textarea, .output-markdown { border-radius: 15px !important; border: 2px solid rgba(255,255,255,0.3) !important; background: rgba(255,255,255,0.95) !important; } button { background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%) !important; border-radius: 10px !important; font-weight: 600 !important; } """ # ========================= # Interface (UNCHANGED) # ========================= iface = gr.Interface( fn=classify_text, inputs=gr.Textbox( lines=8, placeholder="✍️ Paste or type text here to analyze...", label="Enter Text" ), outputs=gr.HTML(label="Analysis Result"), title="
🔍 AI Text Classifier
", description="
Detect whether text is human-written or AI-generated using advanced NLP
" "Model by Dergaoui Ayoub
", flagging_mode="never" ) # ========================= # Launch # ========================= iface.launch( theme=gr.themes.Soft( primary_hue="purple", secondary_hue="pink", neutral_hue="slate", font=gr.themes.GoogleFont("Inter") ), css=custom_css, share=False )