alg_app.py 689 B

12345678910111213141516171819202122232425262728293031323334
  1. """
  2. @author: luojunhui
  3. """
  4. from quart import Quart
  5. from similarities import BertSimilarity
  6. from routes import AlgRoutes
  7. from applications import AsyncMySQLClient
  8. app = Quart(__name__)
  9. AsyncMySQL = AsyncMySQLClient(app)
  10. @app.before_serving
  11. async def init():
  12. """
  13. 初始化模型
  14. """
  15. await AsyncMySQL.init_pool()
  16. model = BertSimilarity(model_name_or_path="BAAI/bge-large-zh-v1.5")
  17. app_routes = AlgRoutes(AsyncMySQL, model)
  18. app.register_blueprint(app_routes)
  19. @app.after_serving
  20. async def close_db():
  21. """
  22. 关闭连接
  23. :return:
  24. """
  25. await AsyncMySQL.close_pool()
  26. if __name__ == '__main__':
  27. app.run(debug=True, host="0.0.0.0", port=6060)