akarshan11 commited on
Commit
d286010
·
verified ·
1 Parent(s): 35d245a

Upload 3 files

Browse files
Files changed (3) hide show
  1. main.py +56 -0
  2. model.pkl +3 -0
  3. vectorizer.pkl +3 -0
main.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ def transform_text(text):
11
+ text = text.lower()
12
+ text = nltk.word_tokenize(text)
13
+
14
+ y = []
15
+ for i in text:
16
+ if i.isalnum():
17
+ y.append(i)
18
+
19
+ text = y[:]
20
+ y.clear()
21
+
22
+ for i in text:
23
+ if i not in stopwords.words('english') and i not in string.punctuation:
24
+ y.append(i)
25
+
26
+ text = y[:]
27
+ y.clear()
28
+
29
+ for i in text:
30
+ y.append(ps.stem(i))
31
+
32
+ return ' '.join(y)
33
+
34
+ tfidf = pickle.load(open('vectorizer.pkl', 'rb'))
35
+ model = pickle.load(open('model.pkl', 'rb'))
36
+
37
+ st.title("Email/SMS SPAM Classifier")
38
+
39
+ input_sms = st.text_area("Enter the message")
40
+
41
+ if st.button('Predict'):
42
+
43
+ # 1. preprocess
44
+ transform_sms = transform_text(input_sms)
45
+ # 2. vectorize
46
+ vector_input = tfidf.transform([transform_sms])
47
+ # 3. predict
48
+ result = model.predict(vector_input)[0]
49
+ # 4. Display
50
+ if result == 1:
51
+ st.header("Spam")
52
+ else:
53
+ st.header("Not Spam")
54
+
55
+
56
+
model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:de35ca1483a8de27d7f79035ae47517ce748ed03b664b22f140119cc04f28cf6
3
+ size 96605
vectorizer.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1b0676c55b0b1836d7e18d17a2183444d4bf4cd1dcc6d914d10544f88470b27e
3
+ size 160664