Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spam-Detector

🇬🇧 English · 🇮🇷 فارسی

A lightweight Python-based SMS spam detector using NLP, SVM, and Flet for spam/ham classification.

Overview

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.

Installation

  1. Clone the repository:
    git clone https://github.com/AliAminiCode/Spam-Detector.git
    cd Spam-Detector
  2. Install dependencies:
    pip install -r requirements.txt
  3. Download NLTK data:
    python -c "import nltk; nltk.download('stopwords'); nltk.download('punkt_tab')"

Usage

Run the GUI:

python src/app.py

Enter 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.py

To compare all supported models (SVM, Naive Bayes, Random Forest, XGBoost, KNN, Logistic Regression) without saving any artifacts:

python src/train_spam_classifier.py --mode exploration

To run the test suite:

pytest tests/

Model Performance

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

Screenshots

Check out Spam-Detector in action:

  • Ham Prediction(Dark Mode):
Ham Prediction(Dark Mode)
  • Spam Prediction(Light Mode):
Spam Prediction(Light Mode)

Download Executable

Try the standalone executable, which runs completely offline without needing an internet connection:

Download Exe

Contribute

Found a bug? Report it at https://github.com/AliAminiCode/Spam-Detector/issues.
Developed by Ali Amini.
Licensed under the MIT License.

About

A Python-based SMS spam detector using SVM, featuring a Flet GUI and standalone executable for easy spam/ham classification.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages