-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathautoml_service.py
executable file
·48 lines (35 loc) · 1.15 KB
/
automl_service.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
# -*- coding: utf-8 -*-
"""
automl_service.py
~~~~~~~~~~~~~~~~~
App implements an automl pipeline.
"""
import os
import json
from flask import Flask, request, jsonify
import numpy as np
import pandas as pd
import requests
import sklearn
import resources
from flask_restful import reqparse, abort, Api, Resource
from utilities import build_features, read_file, read_params,\
train_model, ModelFactory
app = Flask(__name__)
api = Api(app)
model_factory = ModelFactory()
api.add_resource(resources.Train, '/train_pipeline',
resource_class_kwargs={'model_factory': model_factory})
api.add_resource(resources.ServePrediction, '/serve_prediction',
resource_class_kwargs={'model_factory': model_factory})
api.add_resource(resources.Models, '/models',
resource_class_kwargs={'model_factory': model_factory})
# note: not used if using gunicorn
if __name__ == "__main__":
if os.environ.get('VCAP_SERVICES') is None: # running locally
PORT = 8080
DEBUG = True
else: # running on CF
PORT = int(os.getenv("PORT"))
DEBUG = False
app.run(host='0.0.0.0', port=PORT, debug=DEBUG)