kartavya17
commited on
Commit
•
dc4fd58
1
Parent(s):
7b3dbf3
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
import sklearn
|
8 |
+
|
9 |
+
ps = PorterStemmer()
|
10 |
+
|
11 |
+
def Datapreprocessing(text):
|
12 |
+
text = text.lower()
|
13 |
+
text = nltk.word_tokenize(text)
|
14 |
+
|
15 |
+
y = []
|
16 |
+
|
17 |
+
for i in text:
|
18 |
+
if i.isalnum():
|
19 |
+
y.append(i)
|
20 |
+
text = y.copy()
|
21 |
+
y.clear()
|
22 |
+
|
23 |
+
for i in text:
|
24 |
+
if i not in string.punctuation and i not in stopwords.words('english'):
|
25 |
+
y.append(i)
|
26 |
+
|
27 |
+
text = y.copy()
|
28 |
+
y.clear()
|
29 |
+
|
30 |
+
for i in text:
|
31 |
+
y.append(ps.stem(i))
|
32 |
+
|
33 |
+
text = y[:]
|
34 |
+
y.clear()
|
35 |
+
|
36 |
+
text = " ".join(text)
|
37 |
+
return text
|
38 |
+
|
39 |
+
tfidf = pickle.load(open('vectorizer.pkl','rb'))
|
40 |
+
model = pickle.load(open('model.pkl','rb'))
|
41 |
+
|
42 |
+
st.title('Email/SMS Spam Classifier ')
|
43 |
+
|
44 |
+
|
45 |
+
input_sms = st.text_area('Enter the EmailSMS : ')
|
46 |
+
|
47 |
+
if st.button('Predict'):
|
48 |
+
|
49 |
+
# 1. preprocess
|
50 |
+
transformed_sms = Datapreprocessing(input_sms)
|
51 |
+
# 2. vectorize
|
52 |
+
vector_input = tfidf.transform([transformed_sms])
|
53 |
+
# 3. predict
|
54 |
+
result = model.predict(vector_input)[0]
|
55 |
+
# 4. Display
|
56 |
+
if result == 1:
|
57 |
+
st.header("Spam ! Be Careful AMIGO ;)")
|
58 |
+
else:
|
59 |
+
st.header("Not Spam ! Go ahead buddy :D ")
|