dim_classify_app.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from gevent import monkey; monkey.patch_all()
  2. from flask import Flask, request, jsonify
  3. from gevent.pywsgi import WSGIServer
  4. import config
  5. from log_config import LogConfig
  6. from dim_classify import *
  7. app = Flask(__name__)
  8. # hnsw模型数据检索
  9. @app.route('/dim_classify', methods=['GET', 'POST'])
  10. def retrieve():
  11. if request.method == 'POST':
  12. # 获取post数据
  13. retrieve_dict = request.get_json()
  14. # 接收日志采集
  15. dc_logger.info(config.log_msg.format(id="多维分类",
  16. type="dim_classify接收",
  17. message=retrieve_dict))
  18. sentence = retrieve_dict["sentence"]
  19. questype = retrieve_dict["quesType"]
  20. # 多维分类
  21. res_list = dim_classify(sentence, questype)
  22. # 返回日志采集
  23. dc_logger.info(config.log_msg.format(id="多维分类",
  24. type="dim_classify返回",
  25. message=res_list))
  26. return jsonify(res_list)
  27. if __name__ == '__main__':
  28. # 日志采集初始化
  29. dc_LogConfig = LogConfig(config.retrieval_path, "dim_classify")
  30. dc_logger = dc_LogConfig.get_log()
  31. # 多维分类模型初始化
  32. dim_classify = Dimension_Classification()
  33. # app.run(host='0.0.0.0',port='8837')
  34. server = WSGIServer(('0.0.0.0', 8837), app)
  35. server.serve_forever()