-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
43 lines (30 loc) · 1.05 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
43
from flask import Flask, render_template,request
import re
from nltk.stem import WordNetLemmatizer
import pickle
wo = WordNetLemmatizer()
app = Flask(__name__)
def preprocess(data):
#preprocess
a = re.sub('[^a-zA-Z]',' ',data)
a = a.lower()
a = a.split()
a = [wo.lemmatize(word) for word in a ]
a = ' '.join(a)
return a
tfidf_vectorizer = pickle.load(open('vectorizer.pkl','rb'))
model = pickle.load(open('prediction.pkl','rb'))
@app.route('/')
def home():
return render_template('index.html')
@app.route('/predict', methods= ['POST'])
def predict():
msg = request.form['mood_pred']
a = preprocess(msg)
# example_counts = vectorizer.transform( [a] )
# prediction = mnb.predict( example_counts )
# prediction[0]
result = model.predict(tfidf_vectorizer.transform([a]))[0]
return render_template('index.html',pred = "You are {}".format("as happy as a flying penguin." if (result == 0) else "a little bit sad.."))
if __name__ == '__main__':
app.run(debug=True)