avngrstark commited on
Commit
92f71fb
·
verified ·
1 Parent(s): 2d965df

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pickle
2
+ import nltk
3
+ import re
4
+ from nltk.corpus import stopwords
5
+ from nltk.stem import PorterStemmer
6
+ from nltk.stem import WordNetLemmatizer
7
+ import streamlit as st
8
+
9
+ stemmer = PorterStemmer()
10
+ lemmatizer = WordNetLemmatizer()
11
+
12
+ cv = pickle.load(open('pickle_files/
13
+ count_vectorizer.pkl', 'rb'))
14
+
15
+ model = pickle.load(open('pickle_files/spam_model.pkl', 'rb'))
16
+
17
+
18
+ def spam_or_ham(message):
19
+ message = re.sub('[^a-zA-Z]', ' ', message)
20
+ message = message.lower()
21
+ message = message.split()
22
+ message = [lemmatizer.lemmatize(word) for word in message if word not in set(stopwords.words('english'))]
23
+ message = ' '.join(message)
24
+
25
+ X = cv.transform([message]).toarray()
26
+ prediction = model.predict(X)
27
+ if prediction:
28
+ return 'Not Spam'
29
+ else:
30
+ return 'Spam'
31
+
32
+
33
+ st.title("Spam Classifier")
34
+
35
+ message = st.text_input("Type a Message")
36
+
37
+ if st.button("Check Spam or Ham"):
38
+ if message:
39
+ spam_check = spam_or_ham(message)
40
+ st.write(spam_check)
41
+ else:
42
+ st.write('Empty Message')