forked from vyashemang/flask-salary-predictor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
35 lines (26 loc) · 885 Bytes
/
server.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
# Create API of ML model using flask
'''
This code takes the JSON data while POST request an performs the prediction using loaded model and returns
the results in JSON format.
'''
# Import libraries
import numpy as np
from flask import Flask, request, jsonify
import pickle
app = Flask(__name__)
# Load the model
model = pickle.load(open('model.pkl','rb'))
@app.route('/api/',methods=['POST'])
def predict():
# Get the data from the POST request.
data = request.get_json(force=True)
# Make prediction using model loaded from disk as per the data.
prediction = model.predict([[np.array(data['exp'])]])
# Take the first value of prediction
output = prediction[0]
return jsonify(output)
if __name__ == '__main__':
try:
app.run(port=5000, debug=True)
except:
print("Server is exited unexpectedly. Please contact server admin.")