-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
67 lines (43 loc) · 1.23 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import pickle
from flask_cors import CORS
# load the model
model = pickle.load(open('finalized_model.sav', 'rb'))
# load the vectorizer
vectorizer = pickle.load(open('vectorizer.pickle', 'rb'))
def preprocess(text):
text = text.lower()
return text
# make a prediction
def pred(text):
predicted=(model.predict(vectorizer.transform(text)))
return str(predicted[0])
from flask import Flask,request, jsonify
import json
app = Flask(__name__)
CORS(app)
@app.route('/predict', methods=['GET','POST'])
def check():
if request.method == 'POST':
data = (request.form.get('text'))
print(data)
if data is None:
return jsonify({"message":"text not found"})
else:
text=preprocess(data)
text=[text]
ans=pred(text)
response=jsonify(
{
"predicted": ans
}
)
return response
else:
return 'send the data through POST method'
@app.route('/', methods=['GET','POST'])
def index():
return 'Machine Learning Inference'
if __name__ == '__main__':
app.run(port='51',debug=True)
## deployed at heroku
# https://la-identification.herokuapp.com/predict