-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication.py
41 lines (32 loc) · 1.04 KB
/
application.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
from aiohttp import web
import json
from finance_model import Model
async def predict(request):
global model
text = await request.text()
client_id = json.loads(text)['clientId']
try:
mean, count = model.predict(client_id)
except RuntimeError:
return web.Response(headers={
"Access-Control-Allow-Origin" : "*",
}, status=404)
data = {"contributionMoney" : mean, "contributionsNumber" : count}
return web.json_response(data, headers={
"Access-Control-Allow-Origin" : "*",
}, status=200)
async def options(reuest):
return web.Response(headers={
"Access-Control-Allow-Origin" : "*",
"Access-Control-Allow-Headers" : "*",
}, status=200)
app = web.Application()
app.add_routes([web.post('/predict', predict),
web.options('/predict', options)])
model = Model(
'data/external_features.frt',
'data/npo_clnts.csv',
'data/npo_cntrbtrs.csv',
'data/correct_target.frt')
if __name__ == '__main__':
web.run_app(app, port=8050)