Mvrick3027 commited on
Commit
9b504eb
·
1 Parent(s): 077824c
Files changed (1) hide show
  1. app.py +54 -0
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 transform_text(text):
12
+ text = text.lower()
13
+ text = nltk.word_tokenize(text)
14
+
15
+ y = []
16
+ for i in text:
17
+ if i.isalnum():
18
+ y.append(i)
19
+
20
+ text = y[:]
21
+ y.clear()
22
+
23
+ for i in text:
24
+ if i not in stopwords.words('english') and i not in string.punctuation:
25
+ y.append(i)
26
+
27
+ text = y[:]
28
+ y.clear()
29
+
30
+ for i in text:
31
+ y.append(ps.stem(i))
32
+
33
+ return " ".join(y)
34
+
35
+ tfidf = pickle.load(open('vectorizer.pkl','rb'))
36
+ model = pickle.load(open('model.pkl','rb'))
37
+
38
+ st.title("offensive Text Classifier")
39
+
40
+ input_sms = st.text_input("Enter the message")
41
+
42
+ if st.button('predict'):
43
+
44
+
45
+ transformed_sms = transform_text(input_sms)
46
+
47
+ vector_input = tfidf.transform([transformed_sms])
48
+
49
+ result = model.predict(vector_input)[0]
50
+
51
+ if result == 1:
52
+ st.header("offensive")
53
+ else:
54
+ st.header("non-offensive")