-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
82 lines (69 loc) · 1.86 KB
/
Copy pathapp.py
File metadata and controls
82 lines (69 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import streamlit as st
import pickle
import string
import nltk
from nltk.corpus import stopwords
from nltk.stem.porter import PorterStemmer
nltk.download('punkt')
nltk.download('stopwords')
ps = PorterStemmer()
#this function can also be exported using pickle
def transform_text(text):
text = text.lower() #convert to lowercase
text = nltk.word_tokenize(text) #create a list of all the words
y = [] #removing special characters
for i in text:
if i.isalnum():
y.append(i)
text = y[:]
y.clear()
for i in text:
if i not in stopwords.words('english') and i not in string.punctuation:
y.append(i)
text = y[:]
y.clear()
for i in text:
y.append(ps.stem(i))
return " ".join(y)
tfidf = pickle.load(open('vectorizer.pkl', 'rb'))
model = pickle.load(open('model.pkl', 'rb'))
# Add css to make text bigger
st.markdown(
"""
<style>
textarea {
font-size: 1.5rem !important;
}
input {
font-size: 3rem !important;
}
label{
font-size: 89rem !important;
}
.css-1yy6isu p {
word-break: break-word;
font-size: 40px;
}
p, ol, ul, dl {
margin: 0px 0px 1rem;
padding: 0px;
font-size: 1.5rem;
font-weight: 400;
}
</style>
""",
unsafe_allow_html=True,
)
st.title("Email/SMS Spam Classifier")
# original_title = '<p style="font-family:Sans serif; font-size: 40px;">Enter the Message</p>'
# st.markdown(original_title, unsafe_allow_html=True)
input_sms = st.text_area(label = "Enter the Message" )
if st.button('Predict'):
# 1. preprocessing 2. vectorize 3. predict 4. display
transformed_sms = transform_text(input_sms)
vector_input = tfidf.transform([transformed_sms])
result = model.predict(vector_input)[0]
if result == 1:
st.header("Spam")
else:
st.header("Not Spam")