alg_app.py 810 B

123456789101112131415161718192021222324252627282930313233343536
  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. from applications.embedding_manager import EmbeddingManager
  9. app = Quart(__name__)
  10. AsyncMySQL = AsyncMySQLClient(app)
  11. @app.before_serving
  12. async def init():
  13. """
  14. 初始化模型
  15. """
  16. await AsyncMySQL.init_pool()
  17. model = BertSimilarity(model_name_or_path="BAAI/bge-large-zh-v1.5")
  18. embedding_manager = EmbeddingManager(model)
  19. print("模型加载成功")
  20. app_routes = AlgRoutes(AsyncMySQL, model, embedding_manager)
  21. app.register_blueprint(app_routes)
  22. @app.after_serving
  23. async def close_db():
  24. """
  25. 关闭连接
  26. :return:
  27. """
  28. await AsyncMySQL.close_pool()
  29. if __name__ == '__main__':
  30. app.run()