generated from sub-mod/s2i-flask-notebook
-
Notifications
You must be signed in to change notification settings - Fork 8
/
wsgi.py
107 lines (97 loc) · 2.53 KB
/
wsgi.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# If a file named wsgi.py is present in your repository,
# it will be used as the entry point to your application.
# This can be overridden with the environment variable APP_MODULE.
import json
from flask import Flask, jsonify, request
from prediction import predict, predict1, predict2, predict3
from functools import wraps
from time import time
application = Flask(__name__)
def timing(f):
@wraps(f)
def wrap(*args, **kw):
ts = time()
result = f(*args, **kw)
te = time()
print('func:%r args:[%r, %r] took: %2.4f sec' %(f.__name__, args, kw, te-ts))
return result
return wrap
@application.route('/')
@application.route('/status')
@timing
def status():
return jsonify({'status': 'ok'})
# v3
# The older model
# doesn't use ship_locations
# attacks center
@application.route('/prediction1', methods=['POST'])
@timing
def object_detection1():
data = request.json
# data = json.dumps(data)
# body = json.loads(data)
res = []
try:
print(data)
# bState = data['board_state']
res = jsonify(predict1(data))
return res
except Exception as e:
print('ERROR!!!', e)
return jsonify([])
# v4
# use ship_locations
# attacks center
@application.route('/prediction2', methods=['POST'])
@timing
def object_detection2():
data = request.json
# data = json.dumps(data)
# body = json.loads(data)
res = []
try:
print(data)
# bState = data['board_state']
res = jsonify(predict2(data))
return res
except Exception as e:
print('ERROR!!!', e)
return jsonify([])
# v5
# use ship_locations
# attacks center+random
@application.route('/prediction3', methods=['POST'])
@timing
def object_detection3():
data = request.json
# data = json.dumps(data)
# body = json.loads(data)
res = []
try:
print(data)
# bState = data['board_state']
res = jsonify(predict3(data))
return res
except Exception as e:
print('ERROR!!!', e)
return jsonify([])
# v6
# use ship_locations
# attacks based on previous probs then center
@application.route('/prediction', methods=['POST'])
def object_detection():
data = request.json
# data = json.dumps(data)
# body = json.loads(data)
res = []
try:
print("model_v6")
print(data)
# bState = data['board_state']
res = predict(data)
res1 = jsonify(res)
return res1
except Exception as e:
print('ERROR!!!', e)
return jsonify([])