import joblib import re import string # ๐Ÿงน Reuse the same clean_text function def clean_text(text): text = text.lower() text = re.sub(r'\d+', '', text) # remove numbers text = text.translate(str.maketrans('', '', string.punctuation)) # remove punctuation text = text.strip() return text # ๐Ÿ’พ Load the saved model and vectorizer model = joblib.load("spam_detection_model.pkl") vectorizer = joblib.load("spam_detection_vectorizer.pkl") # ๐Ÿ’ฌ Function to predict a new message def predict_message(msg): msg_clean = clean_text(msg) msg_vec = vectorizer.transform([msg_clean]) pred = model.predict(msg_vec)[0] return "๐Ÿšจ Spam" if pred == 1 else "โœ… Not Spam" # ๐Ÿงช Test with some examples print(predict_message("Congratulations! You have won a car")) print(predict_message("Hey, click here to claim your reward")) print(predict_message("Exclusive offer! Click here to claim your reward now"))