Created
September 2, 2018 07:28
-
-
Save maxpagels/55d6f940299179a3c4d5c0a37632de28 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
from flask import Flask | |
from flask import jsonify | |
from flask import request | |
VW_HOST = '127.0.0.1' | |
VW_PORT = 26542 | |
BUFFER_SIZE = 1024*10 | |
app = Flask(__name__) | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.connect((VW_HOST, VW_PORT)) | |
@app.route('/train', methods=['POST']) | |
def train(): | |
body = request.get_json() | |
req = '{0} | {1}\n'.format( | |
body['response'], | |
body['context'] | |
).encode() | |
s.sendall(req) | |
data = float(s.recv(BUFFER_SIZE).decode('utf-8').strip()) | |
return jsonify({'prediction': float(data)}) | |
@app.route('/save', methods=['POST']) | |
def save(): | |
body = request.get_json() | |
filename = body['filename'] | |
req = 'save_{0}\n'.format(filename).encode() | |
s.sendall(req) | |
return jsonify({'model file': filename}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment