alg_app.py 839 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. """
  2. @author: luojunhui
  3. """
  4. import os
  5. from quart import Quart
  6. from similarities import BertSimilarity
  7. from routes import AlgRoutes
  8. from applications import AsyncMySQLClient
  9. from applications.embedding_manager import EmbeddingManager
  10. app = Quart(__name__)
  11. AsyncMySQL = AsyncMySQLClient(app)
  12. @app.before_serving
  13. async def init():
  14. """
  15. 初始化模型
  16. """
  17. await AsyncMySQL.init_pool()
  18. model = BertSimilarity(model_name_or_path="BAAI/bge-large-zh-v1.5", device="cuda:1")
  19. embedding_manager = EmbeddingManager(model)
  20. print("模型加载成功")
  21. app_routes = AlgRoutes(AsyncMySQL, model, embedding_manager)
  22. app.register_blueprint(app_routes)
  23. @app.after_serving
  24. async def close_db():
  25. """
  26. 关闭连接
  27. :return:
  28. """
  29. await AsyncMySQL.close_pool()
  30. if __name__ == '__main__':
  31. app.run()