From ff69909e62c7e37a07e1d0594effd82d9c8d00c6 Mon Sep 17 00:00:00 2001 From: lechatpito Date: Fri, 3 Oct 2014 12:41:08 -0400 Subject: [PATCH] more cowwwbell --- word2vec-api.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/word2vec-api.py b/word2vec-api.py index 4c7210b..852aa0c 100644 --- a/word2vec-api.py +++ b/word2vec-api.py @@ -13,6 +13,8 @@ from numpy import exp, dot, zeros, outer, random, dtype, get_include, float32 as REAL,\ uint32, seterr, array, uint8, vstack, argsort, fromstring, sqrt, newaxis, ndarray, empty, sum as np_sum import argparse +import base64 +import sys parser = reqparse.RequestParser() @@ -62,9 +64,11 @@ def get(self): args = parser.parse_args() try: res = model[args['word']] - return res.tostring() + str = base64.b64encode(res) + return str except: - return + sys.exc_info()[0] + return app = Flask(__name__) api = Api(app) @@ -100,5 +104,4 @@ def raiseError(error): if not args.model: print "Usage: wor2vec-apy.py --model path/to/the/model [--host host --port 1234]" model = w.load_word2vec_format(model_path, binary=binary) - app.run(host=host, port=port) - + app.run(host=host, port=port)