darkneuron-spamdex-v1 / example_usage.py
DarkNeuron-AI's picture
Upload 3 files
23fafc3 verified
raw
history blame contribute delete
964 Bytes
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"))