-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
executable file
·39 lines (31 loc) · 1.14 KB
/
app.py
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
# Importing essential libraries
from flask import Flask, render_template, request
import pickle
#pre processing models
import nltk
nltk.download('stopwords')
from nltk.corpus import stopwords
from nltk.stem.porter import PorterStemmer
import re
# Load the Multinomial Naive Bayes model and CountVectorizer object from disk
cv = pickle.load(open('cv-transform.pkl','rb'))
classifier = pickle.load(open('restaurant-sentiment-mnb-model.pkl', 'rb'))
app = Flask(__name__)
@app.route('/')
def home():
return render_template('index.html')
@app.route('/predict', methods=['POST'])
def predict():
if request.method == 'POST':
ps=PorterStemmer()
message = request.form['message']
message = re.sub('[^a-zA-Z]',' ',message).lower().split()
review_words = [word for word in message if not word in set(stopwords.words('english'))-{'not'}]
review = [ps.stem(word) for word in review_words]
review = ' '.join(review)
data=[review]
vect = cv.transform(data).toarray()
my_prediction = classifier.predict(vect)
return render_template('result.html', prediction=my_prediction)
if __name__ == '__main__':
app.run(debug=True)