Downloads · 30 days
0
PrasadAdsul21/SMS-spam-classification
SMS-spam-classification is a text classification model from PrasadAdsul21. Use it when you need a label for a piece of text. The card lists the license as bsd-3-clause.
<p align="right"(<a href="readme-top"back to top</a)</p
Downloads · 30 days
0
Access
Public
Updated Feb 20, 2024
Repo size
257 KB
Likes
1
Public
Click a slice to open those files.
.ipynb1.5 MB · 67%
From the Hugging Face model README
import streamlit as st
import pickle
import string
import pickle
from nltk.corpus import stopwords
import nltk
from nltk.stem.porter import PorterStemmer
nltk.download('stopwords') # Downloading stopwords data
nltk.download('punkt') # Downloading tokenizer data
ps = PorterStemmer()
def transform_text(text):
text = text.lower()
text = nltk.word_tokenize(text)
y = []
for i in text:
if i.isalnum():
y.append(i)
text = y[:]
y.clear()
for i in text:
if i not in stopwords.words('english') and i not in string.punctuation:
y.append(i)
text = y[:]
y.clear()
for i in text:
y.append(ps.stem(i))
return " ".join(y)
tfidf = pickle.load(open('vectorizer.pkl','rb'))
model = pickle.load(open('model.pkl','rb'))
st.title("Email/SMS Spam Classifier")
input_sms = st.text_area("Enter the message")
if st.button('Predict'):
# 1. preprocess
transformed_sms = transform_text(input_sms)
# 2. vectorize
vector_input = tfidf.transform([transformed_sms])
# 3. predict
result = model.predict(vector_input)[0]
# 4. Display
if result == 1:
st.header("Spam")
else:
st.header("Not Spam")
<p align="right">(<a href="#readme-top">back to top</a>)</p>