animay620 commited on
Commit
57b8063
1 Parent(s): 6c5362c

Upload 5 files

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