-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
42 lines (32 loc) · 1.21 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
40
41
42
from flask import Flask,render_template,url_for,request
import pandas as pd
import pickle
from sklearn.feature_extraction.text import CountVectorizer
from skmultilearn.problem_transform import BinaryRelevance
from sklearn.naive_bayes import MultinomialNB
from sklearn.externals import joblib
app = Flask(__name__)
@app.route('/')
def home():
return render_template('home.html')
@app.route('/predict',methods=['POST'])
def predict():
print("In predict .............")
tcc_model = open('model_MNB.pkl','rb')
print("Model pickle opened .......")
clf = joblib.load(tcc_model)
print("Model pickle LOADed .......")
tcc_vect = open('vectorizer.pkl','rb')
print("Vectorizer pickle opened .......")
vectz = joblib.load(tcc_vect)
print("Vectorizer pickle LOADed .......")
if request.method == 'POST':
message = request.form['message']
#message must contain our comment in string format
data = [message]
#test_str_dtm = vectz.transform(data).toarray()
test_str_dtm = vectz.transform(data)
my_prediction = clf.predict(test_str_dtm).toarray().tolist()
return render_template('result.html',prediction = my_prediction[0])
if __name__ == '__main__':
app.run(debug=True)