import gradio as gr from setfit import SetFitModel MODEL_ID = "jjprietotorres/labse-persuasion-detection-agnostic" # Load model model = SetFitModel.from_pretrained(MODEL_ID) # Define class labels labels = ["Supply Scarcity", "Authority Endorsement", "Misrepresentation", "Neutral", "Logical Appeal"] def classify_text(text): """Classify input text and show persuasion category probabilities.""" text = text.strip() if not text: return "⚠️ Please enter some text to analyze." # Get probability predictions probas = model.predict_proba([text]) # Zip labels with probabilities label_scores = list(zip(labels, probas[0].tolist())) label_scores = sorted(label_scores, key=lambda x: x[1], reverse=True) # Build Markdown report report_lines = [f"### 🔍 Analysis Result for:\n> {text}\n"] report_lines.append("\n**Predicted persuasion categories:**\n") for label, score in label_scores: bar = "█" * int(score * 20) report_lines.append(f"- **{label}**: {score:.2f} {bar}") return "\n".join(report_lines) # Define Gradio interface demo = gr.Interface( fn=classify_text, inputs=gr.Textbox(lines=4, placeholder="Enter text to analyze persuasion...", label="Input Text"), outputs=gr.Markdown(label="Classification Report"), title="🧠 Persuasion Detection (LaBSE + SetFit)", description=( "Detect persuasive intent in text.\n\n" "Model: `jjprietotorres/labse-persuasion-detection-agnostic`\n" "Classes: Supply Scarcity · Authority Endorsement · Misrepresentation · Logical Appeal · Neutral\n\n" "Part of the **Time to Trust AI** initiative." ), theme="soft", examples=[ ["Experts agree this is the only viable solution."], ["Hurry, offer ends tonight!"], ["Data clearly supports our argument."], ["I think everyone should consider this approach carefully."], ], ) if __name__ == "__main__": demo.launch()