Views
No views yet
spam_detection_model.pkl → Trained Naive Bayes modelspam_detection_vectorizer.pkl → TF-IDF vectorizer for text preprocessingexample_usage.py → Example code to use the modelrequirements.txt → Dependencies list1from huggingface_hub import hf_hub_download
2import joblib
3import string
4import re
5
6# Download and load the vectorizer
7vectorizer_path = hf_hub_download("DarkNeuron-AI/darkneuron-spamdex-v1", "spam_detection_vectorizer.pkl")
8vectorizer = joblib.load(vectorizer_path)
9
10# Download and load the trained model
11model_path = hf_hub_download("DarkNeuron-AI/darkneuron-spamdex-v1", "spam_detection_model.pkl")
12model = joblib.load(model_path)
13
14# Text cleaning function
15def clean_text(text):
16 text = text.lower() # lowercase
17 text = re.sub(r'\d+', '', text) # remove digits
18 text = text.translate(str.maketrans('', '', string.punctuation)) # remove punctuation
19 return text.strip() # remove extra spaces
20
21# Example usage
22email_text = "Congratulations! You are the topper!"
23cleaned_email = clean_text(email_text)
24
25# Wrap text in a list for vectorizer
26email_vector = vectorizer.transform([cleaned_email])
27
28# Predict
29prediction = model.predict(email_vector)
30
31print("Prediction:", "🚨 Spam" if prediction[0] == 1 else "✅ Not Spam")