🇬🇧 English · 🇮🇷 فارسی
A lightweight Python-based SMS spam detector using NLP, SVM, and Flet for spam/ham classification.
Spam-Detector classifies SMS messages as spam or ham using Natural Language Processing (NLP) for text preprocessing, a Support Vector Machine (SVM) for machine learning-based classification, and a Flet GUI for user interaction. It offers a simple interface with theme switching and a standalone executable for offline use. Key features:
- NLP: Tokenization, stemming, and stopword removal for message preprocessing.
- SVM: Accurate spam/ham classification using a trained model.
- Flet GUI: User-friendly interface for instant predictions with light/dark theme support.
- Offline support with bundled models and NLTK data.
- Error handling displayed in the GUI.
- Clone the repository:
git clone https://github.com/AliAminiCode/Spam-Detector.git cd Spam-Detector - Install dependencies:
pip install -r requirements.txt
- Download NLTK data:
python -c "import nltk; nltk.download('stopwords'); nltk.download('punkt_tab')"
Run the GUI:
python src/app.pyEnter a message (e.g., "Win a free iPhone!" for spam) to see predictions.
To train the production model (trains SVM and saves it to models/):
python src/train_spam_classifier.pyTo compare all supported models (SVM, Naive Bayes, Random Forest, XGBoost, KNN, Logistic Regression) without saving any artifacts:
python src/train_spam_classifier.py --mode explorationTo run the test suite:
pytest tests/Several models were trained and compared on the same TF-IDF features (unigrams + bigrams). SVM had the best F1 score and is used as the production model:
| Model | Accuracy | Precision | Recall | F1 Score |
|---|---|---|---|---|
| SVM | 0.9839 | 0.9645 | 0.9128 | 0.9379 |
| Naive Bayes | 0.9713 | 0.9916 | 0.7919 | 0.8806 |
| Random Forest | 0.9794 | 1.0000 | 0.8456 | 0.9164 |
| XGBoost | 0.9758 | 0.9485 | 0.8658 | 0.9053 |
| KNN | 0.9139 | 1.0000 | 0.3557 | 0.5248 |
| Logistic Regression | 0.9776 | 0.9189 | 0.9128 | 0.9158 |
Check out Spam-Detector in action:
- Ham Prediction(Dark Mode):
- Spam Prediction(Light Mode):
Try the standalone executable, which runs completely offline without needing an internet connection:
Found a bug? Report it at https://github.com/AliAminiCode/Spam-Detector/issues.
Developed by Ali Amini.
Licensed under the MIT License.

