Skip to content

Latest commit

 

History

History
93 lines (60 loc) · 2.51 KB

README.md

File metadata and controls

93 lines (60 loc) · 2.51 KB

SMS Spam Classification

This project is a web service for SMS spam classification, built using the Flask framework and deployed on Render. 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 and tfidf-vectorizer.pkl files, respectively.

Setup

Prerequisites

  • Python 3.8+

  • nltk

  • scikit-learn

  • Flask

    For more details, refer to the requirements.txt for this project.

Installation

  1. Clone the repository :

    git clone https://github.com/nirmit27/SMS-Spam-Classifier.git
    cd sms-spam-classifier
  2. Install dependencies :

    pip install -r requirements.txt
  3. Run the application locally :

    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 :

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

  • Displaying the classification result as "HAM" or "SPAM" based on the input.

    Result

API Endpoint

POST /api/label

  • Description: Classifies an SMS message as HAM or SPAM.

  • Request Body: JSON object with a single key :

    {
      "message": "Your SMS message here."
    }
  • Response: JSON object with the classification label :

    {
      "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.

License

This project is licensed under the MIT License.