-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
50 lines (40 loc) · 1.49 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
44
45
46
47
48
49
50
from tensorflow.keras.preprocessing.text import Tokenizer
from tensorflow.keras.preprocessing.sequence import pad_sequences
from flask import Flask, render_template, request
import pickle
from tensorflow import keras
from sklearn.preprocessing import MultiLabelBinarizer
from clean_text import clean_text
import numpy as np
cleaner = clean_text()
embedding_dim = 100
max_length = 200
trunc_type='post'
padding_type='post'
# Load tect cleaner
#with open('cleaner.pickle', 'rb') as handle:
# clean = pickle.load(handle)
#load tokenizer
with open('tokenizer.pickle', 'rb') as handle:
tokenizer = pickle.load(handle)
#load multilabel binarizer
with open('binarizer.pickle', 'rb') as handle:
binarizer = pickle.load(handle)
#load model
model = keras.models.load_model("model_glove.h5")
app = Flask(__name__,template_folder='templates')
@app.route('/')
def home():
return render_template('index.html')
@app.route('/predict',methods=['POST'])
def predict():
if request.method == 'POST':
message = request.form['message']
sent = cleaner.do_all(message)
tokens = tokenizer.texts_to_sequences([sent])
pad = pad_sequences(tokens, maxlen=max_length, padding=padding_type, truncating=trunc_type)
x = model.predict(pad)
prediction = binarizer.inverse_transform((x>0.2).astype(np.int))
return render_template('result.html', result=str(prediction)[2:-2])
if __name__ == '__main__':
app.run(debug=True)