Spaces:
Runtime error
Runtime error
import streamlit as st | |
import pickle | |
import numpy as np | |
import pandas as pd | |
import nltk | |
import re | |
from nltk.corpus import stopwords | |
from nltk.stem.porter import PorterStemmer | |
from nltk.stem import WordNetLemmatizer | |
from sklearn.feature_extraction.text import CountVectorizer | |
from sklearn.feature_extraction.text import TfidfVectorizer | |
model = pickle.load(open('spam_model.sav','rb')) | |
tf = pickle.load(open('vectorizer.pkl','rb')) | |
st.title('Spam classifier') | |
input = st.text_area('Enter sms here') | |
ps = PorterStemmer() | |
review = re.sub('[^a-zA-Z]', ' ', input) # to remove punctuation | |
review = review.lower() | |
review = review.split() | |
review = [ps.stem(word) for word in review if not word in stopwords.words('english')] | |
review = ' '.join(review) | |
X = tf.fit_transform(review).toarray() | |
if input: | |
output = model.predict(X) | |
st.json(output) | |