Skip to content

An AI-powered email spam detection system built with machine learning and a beautiful modern web interface.

Notifications You must be signed in to change notification settings

pythonicshariful/Email-Spam-Classifier

Repository files navigation

📧 Email Spam Classifier

An AI-powered email spam detection system built with machine learning and a beautiful modern web interface.

Email Spam Classifier

🌟 Features

  • AI-Powered Detection: Uses TF-IDF vectorization and machine learning to accurately classify spam messages
  • Beautiful Modern UI: Stunning gradient design with smooth animations and glassmorphism effects
  • Real-time Analysis: Instant spam detection with visual feedback
  • Responsive Design: Works seamlessly on desktop, tablet, and mobile devices
  • Easy to Use: Simply paste your message and get instant results

🚀 Live Demo

Try it out: Email Spam Classifier

🛠️ Tech Stack

Backend

  • Python 3.x
  • Flask - Web framework
  • scikit-learn - Machine learning library
  • pickle - Model serialization

Frontend

  • HTML5
  • CSS3 - Custom styling with gradients and animations
  • JavaScript - Interactive functionality
  • Font Awesome - Icons
  • Google Fonts (Inter) - Typography

Machine Learning

  • TF-IDF Vectorization - Text feature extraction
  • Classification Model - Trained on spam dataset
  • Text Preprocessing - Tokenization, stemming, stop word removal

📋 Prerequisites

  • Python 3.7 or higher
  • pip (Python package manager)

🔧 Installation

  1. Clone the repository

    git clone https://github.com/pythonicshariful/Email-Spam-Classifier.git
    cd Email-Spam-Classifier
  2. Create a virtual environment

    python -m venv venv
  3. Activate the virtual environment

    • Windows:
      venv\Scripts\activate
    • macOS/Linux:
      source venv/bin/activate
  4. Install required packages

    pip install flask scikit-learn

🎯 Usage

  1. Start the Flask application

    python app.py
  2. Open your browser Navigate to http://127.0.0.1:5000

  3. Test the classifier

    • Paste any email or message into the text area
    • Click "Analyze Message"
    • Get instant spam detection results!

📊 Model Training

The machine learning model was trained using the following pipeline:

  1. Data Preprocessing

    • Convert text to lowercase
    • Tokenization
    • Remove special characters
    • Remove stop words and punctuation
    • Apply stemming
  2. Feature Extraction

    • TF-IDF (Term Frequency-Inverse Document Frequency) vectorization
  3. Model Training

    • Trained on labeled spam/ham dataset
    • Model saved as model.pkl
    • Vectorizer saved as vectorizer.pkl

See main.ipynb for the complete training process.

📁 Project Structure

Email-Spam-Classifier/
├── app.py                 # Flask application
├── model.pkl              # Trained ML model
├── vectorizer.pkl         # TF-IDF vectorizer
├── main.ipynb            # Model training notebook
├── screenshot.png        # UI screenshot
├── templates/
│   └── index.html        # Web interface
├── dataset/              # Training data
├── venv/                 # Virtual environment
└── README.md            # Project documentation

🎨 UI Features

  • Gradient Background: Eye-catching purple-violet gradient
  • Glassmorphism Card: Modern frosted glass effect
  • Animated Particles: Floating background elements
  • Smooth Transitions: Micro-animations on all interactions
  • Loading States: Visual feedback during analysis
  • Color-coded Results:
    • 🚨 Red for spam detection
    • ✅ Green for safe messages
    • ⚠️ Yellow for warnings
    • ❌ Red for errors

🔍 How It Works

  1. User enters a message in the text area
  2. Frontend sends POST request to /predict endpoint
  3. Backend preprocesses the text using the trained vectorizer
  4. ML model predicts if the message is spam or not
  5. Result is returned as JSON and displayed with beautiful animations

📝 API Endpoints

GET /

Returns the main web interface

POST /predict

Analyzes a message for spam detection

Request Body:

{
  "message": "Your email text here"
}

Response:

{
  "prediction": "Spam" | "Not Spam",
  "message": "Original message"
}

🤝 Contributing

Contributions are welcome! Feel free to:

  • Report bugs
  • Suggest new features
  • Submit pull requests

📄 License

This project is open source and available under the MIT License.

👨‍💻 Author

Shariful Islam

🙏 Acknowledgments

  • Dataset used for training the spam classifier
  • Flask framework for the web application
  • scikit-learn for machine learning capabilities

📧 Contact

For questions or feedback, please open an issue on GitHub.


Made with ❤️ using Machine Learning

About

An AI-powered email spam detection system built with machine learning and a beautiful modern web interface.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published