-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews.py
27 lines (22 loc) · 891 Bytes
/
views.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
from utils import *
from flask import Blueprint,render_template,request
views = Blueprint("views",__name__)
naive_bayes_model = None
tfidf_model = None
@views.route('/',methods=['GET','POST'])
def index():
global naive_bayes_model
global tfidf_model
if request.method == 'POST':
text = request.form.get('textarea')
if(not text):
return render_template('index.html')
if naive_bayes_model is None:
naive_bayes_model = load('models/naive_bayes_model_lite.joblib')
if tfidf_model is None:
tfidf_model = load('models/tfidf_vectorizer_model_lite.joblib')
queries = [text]
results = predict(queries,naive_bayes_model,tfidf_model)
print(results[0])
return render_template('index.html',results=results[0][1],text = text)
return render_template('index.html')