-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
34 lines (25 loc) · 822 Bytes
/
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
from flask import Flask, request, render_template
from preprocess import preprocess
import joblib
import model
app = Flask(__name__)
model.load_model()
clf = joblib.load('classifier.pkl')
vectorizer = joblib.load('vectorizer.pkl')
prediction_cache = {}
@app.route('/')
def index():
return render_template('index.html')
@app.route('/classify', methods=['POST'])
def classify():
sms = request.form['text']
if sms in prediction_cache:
prediction = prediction_cache[sms]
else:
preprocessed_sms = preprocess(sms)
vectorized_text = vectorizer.transform([preprocessed_sms])
prediction = clf.predict(vectorized_text)[0]
prediction_cache[sms] = prediction
return render_template('index.html', result=prediction, sms=sms)
if __name__ == '__main__':
app.run()