-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrediction.py
More file actions
25 lines (18 loc) · 800 Bytes
/
Prediction.py
File metadata and controls
25 lines (18 loc) · 800 Bytes
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
from pickle5 import pickle
from flask import request, Flask,jsonify
app = Flask(__name__)
@app.route('/prediction', methods=['POST'])
def predict():
predictData = request.get_json()
predictdata = predictData['source']['formatFields']
modelFile = pickle.load(open('text_matching.pickle', 'rb'))
model = modelFile['model']
labelEncoder = modelFile['labelEncoder']
count_vec_fit = modelFile['count_vect_fit']
tfidf_fit = modelFile['tfidf_fit']
count_vec_transform = count_vec_fit.transform(predictdata)
tfidf_transform = tfidf_fit.transform(count_vec_transform)
prediction = model.predict(tfidf_transform)
return jsonify({"prediction": labelEncoder.inverse_transform(prediction).tolist()})
if __name__ == '__main__':
app.run(debug=True, port=5002)