alg_app.py 721 B

1234567891011121314151617181920212223242526272829303132333435
  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. print("模型加载成功")
  18. app_routes = AlgRoutes(AsyncMySQL, model)
  19. app.register_blueprint(app_routes)
  20. @app.after_serving
  21. async def close_db():
  22. """
  23. 关闭连接
  24. :return:
  25. """
  26. await AsyncMySQL.close_pool()
  27. if __name__ == '__main__':
  28. app.run(debug=True, host="0.0.0.0", port=6060)