aakritim commited on
Commit
d369eb5
1 Parent(s): a8324d6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -65
app.py CHANGED
@@ -1,65 +1,65 @@
1
- from streamlit_extras.let_it_rain import rain
2
- import streamlit as st
3
- import pickle
4
- import string
5
- from nltk.corpus import stopwords
6
- import nltk
7
- from nltk.stem.porter import PorterStemmer
8
- import sklearn
9
- ps = PorterStemmer()
10
-
11
- def example():
12
- rain(
13
- emoji="❌",
14
- font_size=64,
15
- falling_speed=1.5,
16
- animation_length="10",
17
- )
18
-
19
- def transform_Text(Text):
20
- Text = Text.lower()
21
- Text = nltk.word_tokenize(Text)
22
-
23
- y = []
24
- for i in Text:
25
- if i.isalnum():
26
- y.append(i)
27
-
28
- Text = y[:]
29
- y.clear()
30
-
31
- for i in Text:
32
- if i not in stopwords.words('english') and i not in string.punctuation:
33
- y.append(i)
34
-
35
- Text = y[:]
36
- y.clear()
37
-
38
- for i in Text:
39
- y.append(ps.stem(i))
40
-
41
- return " ".join(y)
42
-
43
-
44
- tfidf = pickle.load(open('vectorizer.pkl', 'rb'))
45
- model = pickle.load(open('model.pkl', 'rb'))
46
-
47
- st.title("SMS SPAM CLASSIFIER/CHECKER")
48
- st.text("")
49
- st.text("")
50
- input_sms = st.text_area("Enter the message...or Copy and Paste the message to detect!! ",)
51
- st.text("")
52
- st.write(f'You wrote {len(input_sms)} characters.')
53
- st.text("")
54
- if st.button("Let's Check"):
55
-
56
- transformed_sms = transform_Text(input_sms)
57
- vector_input = tfidf.transform([transformed_sms])
58
- result = model.predict(vector_input)[0]
59
- if result == 1:
60
- st.warning("OH..NO! IT'S A SPAM !! BEAWARE!")
61
- example()
62
- else:
63
- st.success("RELAX!! IT'S NOT A SPAM !")
64
- st.balloons()
65
-
 
1
+ from streamlit_extras.let_it_rain import rain
2
+ import streamlit as st
3
+ import pickle
4
+ import string
5
+ from nltk.corpus import stopwords
6
+ import nltk
7
+ from nltk.stem.porter import PorterStemmer
8
+ import sklearn
9
+ ps = PorterStemmer()
10
+
11
+ def example():
12
+ rain(
13
+ emoji="❌",
14
+ font_size=64,
15
+ falling_speed=1.5,
16
+ animation_length="10",
17
+ )
18
+
19
+ def transform_Text(Text):
20
+ Text = Text.lower()
21
+ Text = nltk.word_tokenize(Text , preserve_line=True)
22
+
23
+ y = []
24
+ for i in Text:
25
+ if i.isalnum():
26
+ y.append(i)
27
+
28
+ Text = y[:]
29
+ y.clear()
30
+
31
+ for i in Text:
32
+ if i not in stopwords.words('english') and i not in string.punctuation:
33
+ y.append(i)
34
+
35
+ Text = y[:]
36
+ y.clear()
37
+
38
+ for i in Text:
39
+ y.append(ps.stem(i))
40
+
41
+ return " ".join(y)
42
+
43
+
44
+ tfidf = pickle.load(open('vectorizer.pkl', 'rb'))
45
+ model = pickle.load(open('model.pkl', 'rb'))
46
+
47
+ st.title("SMS SPAM CLASSIFIER/CHECKER")
48
+ st.text("")
49
+ st.text("")
50
+ input_sms = st.text_area("Enter the message...or Copy and Paste the message to detect!! ",)
51
+ st.text("")
52
+ st.write(f'You wrote {len(input_sms)} characters.')
53
+ st.text("")
54
+ if st.button("Let's Check"):
55
+
56
+ transformed_sms = transform_Text(input_sms)
57
+ vector_input = tfidf.transform([transformed_sms])
58
+ result = model.predict(vector_input)[0]
59
+ if result == 1:
60
+ st.warning("OH..NO! IT'S A SPAM !! BEAWARE!")
61
+ example()
62
+ else:
63
+ st.success("RELAX!! IT'S NOT A SPAM !")
64
+ st.balloons()
65
+