-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflask_server.py
44 lines (32 loc) · 1 KB
/
flask_server.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
import logging
import torch
import numpy as np
from flask import Flask, request, jsonify
from model import Model
from memory import ReplayMemory
def server(interface):
app = Flask(__name__)
log = logging.getLogger('werkzeug')
log.setLevel(logging.ERROR)
@app.route('/action', methods=['POST'])
def action():
if request.method == 'POST':
content = request.get_json()
state = content['state']
action = interface.get_action(state)
return jsonify({ 'action': action })
@app.route('/transition', methods=['POST'])
def transition():
if request.method == 'POST':
content = request.get_json()
state = content['state']
action = content['action']
reward = content['reward']
next_state = content['next_state']
interface.add_transition(state, action, reward, next_state)
return jsonify({ 'status': 1 })
host = '127.0.0.1'
port = '3000'
print('Server running on {}:{}'.format(host, port))
app.run(host=host, port=port)
return app