An open API service indexing awesome lists of open source software.

https://github.com/farukseker/ml-spam-detection-api

๐Ÿš€ 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 ๐Ÿ“Š.
https://github.com/farukseker/ml-spam-detection-api

fastapi machine-learning model-extraction model-train model-training predict-api prediction prediction-api prediction-model skicit skicit-learn

Last synced: 2 months ago
JSON representation

๐Ÿš€ 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 ๐Ÿ“Š.

Awesome Lists containing this project

README

          

# ๐Ÿ“ง 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

```bash
pip install -r requirements.txt
```

### Running the API

```bash
uvicorn app:app --reload
```

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

```bash
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:

```python
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](docs/spam_pie_chart.png)

> 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:

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

```

#### Response:

```json
{
"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
---