-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
67 lines (53 loc) · 1.76 KB
/
app.py
File metadata and controls
67 lines (53 loc) · 1.76 KB
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
"""
Python script meant to contain API endpoints.
"""
from flask import Flask, request
import json
import os
from diagnostics import model_predictions, dataframe_summary, missing_data, outdated_packages_list, execution_time
from scoring import score_model
# Set up variables for use in our script.
app = Flask(__name__)
app.secret_key = '1652d576-484a-49fd-913a-6879acfa6ba4'
with open('config.json', 'r') as f:
config = json.load(f)
dataset_csv_path = os.path.join(config['output_folder_path'])
prediction_model = None
@app.route("/prediction", methods=['POST', 'OPTIONS'])
def predict():
"""
Prediction Endpoint.
"""
# Call the prediction function you created in Step 3
dataset_path = request.json.get('dataset_path')
y_pred, _ = model_predictions(dataset_path)
return str(y_pred)
@app.route("/scoring", methods=['GET', 'OPTIONS'])
def scoring():
"""
Scoring Endpoint.
"""
# Check the score of the deployed model.
score = score_model()
return str(score)
@app.route("/summarystats", methods=['GET', 'OPTIONS'])
def stats():
"""
Statistics Endpoint.
"""
# Check means, medians, and modes for each column.
summary = dataframe_summary()
return str(summary)
@app.route("/diagnostics", methods=['GET','OPTIONS'])
def diagnostics():
"""
Diagnostics Endpoint.
"""
executiontime = execution_time()
missingdata = missing_data()
outdatedpackages = outdated_packages_list()
return str(
"execution_time:" + executiontime + "\nmissing_data;" + missingdata + "\noutdated_packages:" + outdatedpackages
)
if __name__ == "__main__":
app.run(host='127.0.0.1', port=8000, debug=True, threaded=True)