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
.
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.
-
Python 3.8+
-
nltk
-
scikit-learn
-
Flask
For more details, refer to the requirements.txt for this project.
-
Clone the repository :
git clone https://github.com/nirmit27/SMS-Spam-Classifier.git cd sms-spam-classifier
-
Install dependencies :
pip install -r requirements.txt
-
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.
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."}'
Here are screenshots of the application in action :
-
Taking user input in the text box to classify an SMS message.
-
Displaying the classification result as "HAM" or "SPAM" based on the input.
-
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" }
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.
This project is licensed under the MIT License.