import torch from transformers import AutoTokenizer, AutoModelForSequenceClassification import gradio as gr import os # Path to the saved model directory inside the Space model_dir = "./campaign_bert_model/campaign_bert_model/campaign-bert-model" # Load tokenizer and model try: tokenizer = AutoTokenizer.from_pretrained(model_dir) model = AutoModelForSequenceClassification.from_pretrained(model_dir) model.eval() except Exception as e: raise RuntimeError(f"❌ Failed to load model or tokenizer: {e}") # Map the 5 classes to tones and templates class_map = { 0: ("Informative", "Here are plan details tailored for your interest."), 1: ("Excited", "Great news! You’re eligible for our premium plans!"), 2: ("Neutral", "Explore various insurance options with us."), 3: ("Persuasive", "Take the first step to secure your future today."), 4: ("Empathetic", "We understand your needs—here’s how we can help."), } def predict(text): try: if not text.strip(): return "
📨 Suggested Campaign Message:
{template}
Confidence: {confidence:.2%}
" ) except Exception as e: return f"