

import os

os.environ["CUDA_VISIBLE_DEVICES"] = "1"

from flask import Flask,request,jsonify
app = Flask(__name__)

from BaseDataMaintenance.common.sentencesUtil import *

@app.route("/embedding",methods=["POST"])
def embedding():
    _r = {"success": True}
    try:
        sentence = request.json.get("sentence","")
        vector = get_normalized_vector(sentence)
        _r["vector"] = vector
    except Exception as e:
        _r["success"] = False


    return jsonify(_r)

## 启动方法
## 将此文件放在与BaseDataMaintenance同级下
## nohup /data/anaconda3/envs/py37/bin/gunicorn -w 1 --limit-request-fields 0 --limit-request-line 0 -t 1000 --keep-alive 600 -b 0.0.0.0:17130 embedding_services:app >> embedding.log &

if __name__ == "__main__":
    app.run(host="0.0.0.0",port="15010",debug=True)