Bishawa commited on
Commit
1957ae1
1 Parent(s): 4df37d8

Upload 4 files

Browse files
Files changed (4) hide show
  1. app.py +54 -0
  2. model.pkl +3 -0
  3. spam.csv +0 -0
  4. vectorizer.pkl +3 -0
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pickle
3
+ import string
4
+ from nltk.corpus import stopwords
5
+ import nltk
6
+ from nltk.stem.porter import PorterStemmer
7
+
8
+ ps = PorterStemmer()
9
+
10
+
11
+ def transform_text(text):
12
+ text = text.lower()
13
+ text = nltk.word_tokenize(text)
14
+
15
+ y = []
16
+ for i in text:
17
+ if i.isalnum():
18
+ y.append(i)
19
+
20
+ text = y[:]
21
+ y.clear()
22
+
23
+ for i in text:
24
+ if i not in stopwords.words('english') and i not in string.punctuation:
25
+ y.append(i)
26
+
27
+ text = y[:]
28
+ y.clear()
29
+
30
+ for i in text:
31
+ y.append(ps.stem(i))
32
+
33
+ return " ".join(y)
34
+
35
+ tfidf = pickle.load(open('vectorizer.pkl','rb'))
36
+ model = pickle.load(open('model.pkl','rb'))
37
+
38
+ st.title("Email/SMS Spam Classifier")
39
+
40
+ input_sms = st.text_area("Enter the message")
41
+
42
+ if st.button('Predict'):
43
+
44
+ # 1. preprocess
45
+ transformed_sms = transform_text(input_sms)
46
+ # 2. vectorize
47
+ vector_input = tfidf.transform([transformed_sms])
48
+ # 3. predict
49
+ result = model.predict(vector_input)[0]
50
+ # 4. Display
51
+ if result == 1:
52
+ st.header("Spam")
53
+ else:
54
+ st.header("Not Spam")
model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:437a8b04c78d903dfce054a26dbcb09b001c702b759843507325b78c2707dd5e
3
+ size 96584
spam.csv ADDED
The diff for this file is too large to render. See raw diff
 
vectorizer.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ca9ffddf330f367743ef3d08ec9520f80c57eeda869a9ad852be9695a441bd78
3
+ size 160651