This repository has been archived by the owner on Sep 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
server.py
66 lines (49 loc) · 1.45 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import zmq
import argparse
import json
import os
import numpy as np
import yaml
from flask import Flask, send_from_directory, jsonify, Response, redirect
from flask import request
from flask_cors import CORS
app = Flask(__name__)
CORS(app)
data_handlers = {}
index_map = {}
@app.route('/api/translate/')
def transate():
options = request.args
src = options.get('src')
print("src", src)
sock.send(json.dumps({"src" : src}))
result = sock.recv()
return result
# send everything from client as static content
@app.route('/client/<path:path>')
def send_static(path):
""" serves all files from ./client/ to ``/client/<path:path>``
:param path: path from api call
"""
return send_from_directory('client/', path)
@app.route('/')
def hello_world():
"""
:return: "hello world"
"""
return redirect('client/index.html')
parser = argparse.ArgumentParser()
parser.add_argument("--nodebug", default=False)
parser.add_argument("--port", default="8888")
parser.add_argument("--nocache", default=False)
parser.add_argument("-dir", type=str, default=os.path.abspath('data'))
if __name__ == '__main__':
args = parser.parse_args()
# create_data_handlers(args.dir)
# print args
# ZeroMQ Context
context = zmq.Context()
# Define the socket using the "Context"
sock = context.socket(zmq.REQ)
sock.connect("tcp://127.0.0.1:5556")
app.run(port=int(args.port), debug=not args.nodebug, host="0.0.0.0")