forked from datamites-deployment/heroku-deployment
-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathflaskDeploy.py
63 lines (49 loc) · 1.46 KB
/
flaskDeploy.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
from flask import Flask, request, jsonify
import joblib
import json
from marshmallow import Schema, fields, ValidationError
app = Flask(__name__)
model = joblib.load('model.sav')
class ParameterSchema(Schema):
location = fields.Integer(required=True)
bhk = fields.Integer(required=True)
furnishing = fields.Integer(required=True)
area = fields.Integer(required=True)
old = fields.Integer(required=True)
floor = fields.Integer(required=True)
@app.route('/')
def index():
return 'Hello world'
@app.route('/house_pred',methods = ['POST'])
def predict():
# Get Request body from JSON
request_data = request.json
schema = ParameterSchema()
try:
# Validate request body against schema data types
reqParam = schema.load(request_data)
except ValidationError as err:
# Return a nice message if validation fails
return jsonify(err.messages), 400
# Convert request body back to JSON str
location = reqParam['location']
bhk = reqParam['bhk']
furnishing = reqParam['furnishing']
area = reqParam['area']
old = reqParam['old']
floor = reqParam['floor']
returnJson = {}
# predicting from model
returnJson['price'] = model.predict(
[[
location,
bhk,
furnishing,
area,
old,
floor,
]]
)[0]
return jsonify(returnJson)
if __name__ == '__main__':
app.run(threaded=True, port=5000)