| | import joblib
|
| | import re
|
| | import string
|
| |
|
| |
|
| | def clean_text(text):
|
| | text = text.lower()
|
| | text = re.sub(r'\d+', '', text)
|
| | text = text.translate(str.maketrans('', '', string.punctuation))
|
| | text = text.strip()
|
| | return text
|
| |
|
| |
|
| | model = joblib.load("spam_detection_model.pkl")
|
| | vectorizer = joblib.load("spam_detection_vectorizer.pkl")
|
| |
|
| |
|
| | 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"
|
| |
|
| |
|
| | 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")) |