-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice.py
29 lines (23 loc) · 871 Bytes
/
service.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
#!flask/bin/python
"""
The purpose of this program is to allow users to conveniently query word2vec
in order to save time and make experiments faster.
don't forget to set MODEL_PATH before starting.
"""
global model # I know, I'm sorry...
import os
import gensim
print("Loading... Be patient...")
model = gensim.models.KeyedVectors.load_word2vec_format(os.getenv("MODEL_PATH")+'/GoogleNews-vectors-negative300.bin.gz', binary=True)
print("model Loaded")
from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/get_vec/<string:lwords>/<string:rwords>', methods=['GET'])
def get_vec(lwords, rwords):
global model
return jsonify({'n_similarity': str(model.n_similarity(lwords.split(" "),rwords.split(" ")))})
@app.route('/')
def index():
return jsonify({'res': []})
if __name__ == '__main__':
app.run(host='0.0.0.0',port='7634',debug=True)