Upload 3 files
Browse files- example_usage.py +27 -0
- spam_detection_model.pkl +3 -0
- spam_detection_vectorizer.pkl +3 -0
example_usage.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import joblib
|
| 2 |
+
import re
|
| 3 |
+
import string
|
| 4 |
+
|
| 5 |
+
# 🧹 Reuse the same clean_text function
|
| 6 |
+
def clean_text(text):
|
| 7 |
+
text = text.lower()
|
| 8 |
+
text = re.sub(r'\d+', '', text) # remove numbers
|
| 9 |
+
text = text.translate(str.maketrans('', '', string.punctuation)) # remove punctuation
|
| 10 |
+
text = text.strip()
|
| 11 |
+
return text
|
| 12 |
+
|
| 13 |
+
# 💾 Load the saved model and vectorizer
|
| 14 |
+
model = joblib.load("spam_detection_model.pkl")
|
| 15 |
+
vectorizer = joblib.load("spam_detection_vectorizer.pkl")
|
| 16 |
+
|
| 17 |
+
# 💬 Function to predict a new message
|
| 18 |
+
def predict_message(msg):
|
| 19 |
+
msg_clean = clean_text(msg)
|
| 20 |
+
msg_vec = vectorizer.transform([msg_clean])
|
| 21 |
+
pred = model.predict(msg_vec)[0]
|
| 22 |
+
return "🚨 Spam" if pred == 1 else "✅ Not Spam"
|
| 23 |
+
|
| 24 |
+
# 🧪 Test with some examples
|
| 25 |
+
print(predict_message("Congratulations! You have won a car"))
|
| 26 |
+
print(predict_message("Hey, click here to claim your reward"))
|
| 27 |
+
print(predict_message("Exclusive offer! Click here to claim your reward now"))
|
spam_detection_model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5a5e8a2b1166412aa0127b7617c5980f9851989cb51dbd7b2077ca300f39c095
|
| 3 |
+
size 234551
|
spam_detection_vectorizer.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c9f45dcdab87aa12d74f70d68d094f0fc28cfcb5bd8179789f61bca7e31762fa
|
| 3 |
+
size 149879
|