Skip to content

๐Ÿš€ A FastAPI-powered project that uses a trained ML model to classify incoming emails as spam ๐Ÿ›‘ or ham ๐Ÿ“ง in real-time. Supports CSV batch processing ๐Ÿ“‚, multi-query input ๐Ÿ”„, and detailed logging with usage stats ๐Ÿ“Š.

License

Notifications You must be signed in to change notification settings

farukseker/ML-Spam-Detection-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“ง Spam Mail Detection API

A FastAPI-based project to detect spam emails using machine learning. This repository includes everything from training to deploying a REST API powered by a trained model.


๐Ÿš€ Getting Started

Requirements

  • Python 3.8+ | dev --version: Python 3.13
  • pip

Installation

pip install -r requirements.txt

Running the API

uvicorn app:app --reload

Or using the Procfile (e.g., for Heroku):

web: uvicorn app:app --host=0.0.0.0 --port=${PORT:-8000}

๐Ÿ“Š Dataset Overview

  • Dataset file: email.csv

  • Contains real-world email examples labeled as ham or spam

  • Mapping used in preprocessing:

    df["Category"] = df["Category"].map({"ham": 0, "spam": 1})
  • Total records: [ADD_TOTAL_RECORDS]

    • ๐ŸŸข Ham: [ADD_HAM_COUNT]
    • ๐Ÿ”ด Spam: [ADD_SPAM_COUNT]

๐Ÿ“ˆ Data Distribution

Spam vs Ham Pie Chart

Replace this image path with your actual chart at docs/spam_pie_chart.png


๐Ÿง Model Information

  • Training notebook: Spam Email Detection Machine Learning Train Script.ipynb

  • Saved models:

    • models/spam_model.pkl
    • models/tfidf_vectorizer.pkl

๐Ÿ”ฎ API Usage

Endpoint: POST /predict

Request:

{
  "text": "Congratulations! You've won a free iPhone. Click here to claim."
}

Response:

{
  "prediction": "spam"
}

๐Ÿ“ƒ Notebooks

  • notebooks/Api Example.ipynb: Example API interactions
  • notebooks/Spam Email Detection Machine Learning Train Script.ipynb: Model training and evaluation

๐Ÿ“ File Structure

.
โ”œโ”€โ”€ app.py
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ requirements.lock.txt
โ”œโ”€โ”€ Dockerfile
โ”œโ”€โ”€ docker-compose.yml
โ”œโ”€โ”€ AUTHOR
โ”œโ”€โ”€ data/
โ”‚   โ””โ”€โ”€ email.csv
โ”œโ”€โ”€ models/
โ”‚   โ”œโ”€โ”€ spam_model.pkl
โ”‚   โ””โ”€โ”€ tfidf_vectorizer.pkl
โ”œโ”€โ”€ notebooks/
โ”‚   โ”œโ”€โ”€ Api Example.ipynb
โ”‚   โ””โ”€โ”€ Spam Email Detection Machine Learning Train Script.ipynb
โ””โ”€โ”€ docs/
    โ””โ”€โ”€ spam_pie_chart.png
    โ””โ”€โ”€ avatar.png

๐Ÿ“ข License

GNU Affero General Public License v3.0

Faruk ลŸeker | Code ninja


About

๐Ÿš€ A FastAPI-powered project that uses a trained ML model to classify incoming emails as spam ๐Ÿ›‘ or ham ๐Ÿ“ง in real-time. Supports CSV batch processing ๐Ÿ“‚, multi-query input ๐Ÿ”„, and detailed logging with usage stats ๐Ÿ“Š.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published