Spaces:
Sleeping
Sleeping
| # import streamlit as st | |
| # import pickle | |
| # import string | |
| # from nltk.corpus import stopwords | |
| # import nltk | |
| # from nltk.stem.porter import PorterStemmer | |
| # 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 | |
| # transform_sms = transform_text(input_sms) | |
| # # 2. vectorize | |
| # vector_input = tfidf.transform([transform_sms]) | |
| # # 3. predict | |
| # result = model.predict(vector_input)[0] | |
| # # 4. Display | |
| # if result == 1: | |
| # st.header("Spam") | |
| # else: | |
| # st.header("Not Spam") | |
| import streamlit as st | |
| import pickle | |
| import string | |
| import nltk | |
| from nltk.corpus import stopwords | |
| from nltk.stem.porter import PorterStemmer | |
| # Download NLTK resources if not already downloaded | |
| nltk.download('punkt') | |
| nltk.download('stopwords') | |
| 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 | |
| transform_sms = transform_text(input_sms) | |
| # 2. vectorize | |
| vector_input = tfidf.transform([transform_sms]) | |
| # 3. predict | |
| result = model.predict(vector_input)[0] | |
| # 4. Display | |
| if result == 1: | |
| st.header("Spam") | |
| else: | |
| st.header("Not Spam") | |