-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
46 lines (31 loc) · 1.08 KB
/
app.py
File metadata and controls
46 lines (31 loc) · 1.08 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
import numpy as np
import pandas as pd
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.naive_bayes import MultinomialNB
from flask import Flask, render_template, request
import pickle
cv = pickle.load(open('word_list.pkl', 'rb'))
word_list = cv.get_feature_names()
clf = pickle.load(open('model.pkl', 'rb'))
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/predict', methods=['POST'])
def predict():
review = request.form.get('review')
input_review = transform_review(review)
sentiment = clf.predict(input_review)[0]
print("The sentiment is", sentiment)
if sentiment == 1:
return render_template('index.html', sentiment=1)
else:
return render_template('index.html', sentiment=-1)
def transform_review(review):
count_words = []
for i in word_list:
count_words.append(review.count(i))
input_review = np.array(count_words).reshape(1,3000)
return input_review
if __name__ == "__main__":
app.run(debug=True)