Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nirmit27/sms-spam-classifier
This is a Flask web application for the classification of SMS messages.
https://github.com/nirmit27/sms-spam-classifier
api-rest flask flask-api machine-learning nlp nlp-machine-learning postman python sms-spam-classification sms-spam-detection spam-classification spam-detection
Last synced: 9 days ago
JSON representation
This is a Flask web application for the classification of SMS messages.
- Host: GitHub
- URL: https://github.com/nirmit27/sms-spam-classifier
- Owner: nirmit27
- License: mit
- Created: 2024-10-26T12:18:49.000Z (11 days ago)
- Default Branch: main
- Last Pushed: 2024-10-27T17:45:52.000Z (10 days ago)
- Last Synced: 2024-10-27T22:10:37.781Z (9 days ago)
- Topics: api-rest, flask, flask-api, machine-learning, nlp, nlp-machine-learning, postman, python, sms-spam-classification, sms-spam-detection, spam-classification, spam-detection
- Language: Jupyter Notebook
- Homepage:
- Size: 1.54 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SMS Spam Classification
This project is a web service for SMS spam classification, built using the [**Flask**](https://flask.palletsprojects.com/en/stable/) framework and deployed on [**Render**](https://docs.render.com/free). It leverages a trained machine learning model to classify SMS messages as either `HAM` (legitimate) or `SPAM`.
## Overview
This web service provides a user interface and an API endpoint to classify SMS messages as **spam** or **ham** based on a trained machine learning model. The application utilizes a **Random Forest Classifier** and **TF-IDF vectorizer**, stored in [rfc-model.pkl](./rfc-model.pkl) and [tfidf-vectorizer.pkl](./tfidf-vectorizer.pkl) files, respectively.## Setup
### Prerequisites
* Python 3.8+
* nltk
* scikit-learn
* FlaskFor more details, refer to the [requirements.txt](./requirements.txt) for this project.
### Installation
1. **Clone the repository** :
```bash
git clone https://github.com/nirmit27/SMS-Spam-Classifier.git
cd sms-spam-classifier
```2. **Install dependencies** :
```bash
pip install -r requirements.txt
```3. **Run the application locally** :
```bash
python app.py
```The application will be available at **http://127.0.0.1:5000** if you have followed through correctly.
## Usage
### Local Testing
To classify a message, you can use the `/api/label` endpoint :
```bash
curl -X POST http://127.0.0.1:5000/api/label -H "Content-Type: application/json" -d ' {"message": "Congratulations! You have won a prize."}'
```## Preview
Here are screenshots of the application in action :
* Taking user input in the text box to classify an SMS message.
![User Input](./static/input.png)* Displaying the classification result as "HAM" or "SPAM" based on the input.
![Result](./static/result.png)
## API Endpoint
#### `POST /api/label`
* **Description**: Classifies an SMS message as HAM or SPAM.
* **Request Body**: JSON object with a single key :
```json
{
"message": "Your SMS message here."
}
```* **Response**: JSON object with the classification label :
```json
{
"message": "Your SMS message here.",
"label": "HAM" // or "SPAM"
}
```## Error Handling
The application handles errors with custom templates :* **404 Not Found :** Returns a `404` page if the route does not exist.
* **500 Internal Server Error :** Returns a `500` page for server-related errors.## Deployment
#### **Link** : [Web Service on Render](https://sms-spam-classifier-ofm6.onrender.com/)
> If you are on the **Hobby** plan on Render *(like me)*, mind your **Monthly Free Usage** information.
## License
This project is licensed under the [MIT](https://opensource.org/license/mit) License.