Spaces:
Runtime error
Runtime error
Mvrick3027
commited on
Commit
•
672c237
1
Parent(s):
fa802d8
Delete app.py
Browse files
app.py
DELETED
@@ -1,55 +0,0 @@
|
|
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 |
-
|
8 |
-
ps = PorterStemmer()
|
9 |
-
|
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/Non-Offensive Classifier")
|
39 |
-
|
40 |
-
input_sms = st.text_area("Enter the message")
|
41 |
-
|
42 |
-
if st.button('Predict'):
|
43 |
-
|
44 |
-
# 1. preprocess
|
45 |
-
transformed_sms = transform_text(input_sms)
|
46 |
-
# 2. vectorize
|
47 |
-
vector_input = tfidf.transform([transformed_sms])
|
48 |
-
# 3. predict
|
49 |
-
|
50 |
-
result = model.predict(vector_input)[0]
|
51 |
-
# 4. Display
|
52 |
-
if result == 1:
|
53 |
-
st.header("Offensive")
|
54 |
-
else:
|
55 |
-
st.header("Non-Offensive")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|