This project includes a Flask web application and a machine learning model for classifying emails as either ham (non-spam) or spam. Additionally, a Chrome extension is provided for convenient access to the classification service.
The Flask web application serves as the user interface for email classification. Users can input an email, and the application will classify it as ham or spam using a machine learning model.
app.py
: Main file containing the Flask application, routes, and logic.email_classifier.py
: Module providing functions for loading, preprocessing, training, and classifying emails using a machine learning model.templates/index.html
: HTML template for the main webpage, including a form for entering an email and displaying the classification result.
- User inputs an email on the webpage.
- The input email is sent to the machine learning model for classification.
- The classification result (ham or spam) is displayed on the webpage.
Make sure to install the required Python libraries for the Flask web application:
pip install Flask
pip install scikit-learn
The machine learning model is responsible for training and classifying emails as spam or ham.
machine_learning_model.py
: Python script for loading and preprocessing email data, training a Logistic Regression model, and evaluating its performance.mail_data.csv
: CSV file containing labeled email data for training the machine learning model.
- Load and preprocess labeled email data from
mail_data.csv
. - Train a Logistic Regression model with TF-IDF feature extraction.
- Evaluate the model's performance.
- Classify new emails as spam or ham using the trained model.
Ensure you have the required Python libraries installed for the machine learning model:
pip install pandas
pip install scikit-learn
The Chrome extension provides a quick and easy way for users to interact with the email classification service directly from the browser.
manifest.json
: Manifest file specifying extension details, including permissions, icons, and popup behavior.popup.html
: HTML file defining the structure of the extension's popup.popup.js
: JavaScript file handling the logic for the extension's popup, including opening a new tab with the Flask web application.
- Clicking the extension icon opens a popup with an option to check emails.
- The popup is linked to the Flask web application, allowing users to quickly access the email classification service.
-
Flask Web Application:
- Run the Flask application using
python app.py
. - Open a web browser and visit http://127.0.0.1:5000/.
- Enter an email to view the classification result.
- Run the Flask application using
-
Machine Learning Model:
- Train and evaluate the machine learning model using the
machine_learning_model.py
script. - Customize the script or functions as needed for your specific use case.
- Train and evaluate the machine learning model using the
-
Chrome Extension:
- Load the extension in Chrome:
- Open Chrome and go to
chrome://extensions/
. - Enable "Developer mode" at the top right.
- Click "Load unpacked" and select the extension folder.
- Open Chrome and go to
- Load the extension in Chrome:
To set up the entire system, follow these steps:
-
Clone the Repository:
git clone https://github.com/your-username/your-repository.git cd your-repository
-
Flask Web Application:
- Install dependencies:
pip install Flask scikit-learn
- Run the Flask application:
python app.py
- Open a web browser and go to http://127.0.0.1:5000/.
- Install dependencies:
-
Machine Learning Model:
- Train and evaluate the machine learning model using the
machine_learning_model.py
script. - Customize the script or functions as needed for your specific use case.
- Train and evaluate the machine learning model using the
-
Chrome Extension:
- Open Chrome and go to
chrome://extensions/
. - Enable "Developer mode" at the top right.
- Click "Load unpacked" and select the extension folder.
- Open Chrome and go to