This project consists of a browser extension for spam detection and a FastAPI server that uses machine learning models to classify messages as spam or ham.
This project uses Astral UV for dependency management and virtual environment creation. Follow these steps to set up the project:
-
Install Astral UV if you haven't already:
curl -fsSL https://astral.sh/uv/install.sh | bash -
Clone the repository:
git clone https://github.com/your-username/spam_detector.git cd spam_detector -
Create a virtual environment and install dependencies:
uv venv source .venv/bin/activate uv sync
To set up the browser extension:
-
Open your browser (Chrome, Firefox, etc.) and navigate to the extensions page.
-
Enable "Developer mode".
-
Click on "Load unpacked" or "Load temporary add-on".
-
Navigate to the
extensiondirectory in this project and select it.
The extension should now be loaded and visible in your browser.
To retrain the Random Forest model:
- Ensure you're in the project root directory and your virtual environment is activated.
- Ensure you have the training data
[Dataset](https://www.kaggle.com/datasets/meruvulikith/190k-spam-ham-email-dataset-for-classification)(properly namedspam_Emails_data.csv) and you have put it in the right directoryserver/models/data - Run the training script:
python trainer.py
This will retrain the models using the latest data and save the new model and vectorizer in the server/models/data directory.
To run the FastAPI server:
-
Ensure you're in the project root directory and your virtual environment is activated.
-
Start the server:
fastapi dev main.py
The server will start running on http://127.0.0.1:8000. You can access the API documentation at http://127.0.0.1:8000/docs.
To deploy the project using Docker:
-
Build the Docker image:
docker build -t spam-detector . -
Run the Docker container:
docker run -p 8000:8000 spam-detector
The server will be accessible at http://localhost:8000.
- The main server logic is in
server/routes.py. - The machine learning models are located in the
server/modelsdirectory. - The browser extension files are in the
extensiondirectory.
For more detailed information about each component, please refer to the comments in the respective files.