alg_app.py 840 B

12345678910111213141516171819202122232425262728293031323334353637
  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. embedding_manager = EmbeddingManager()
  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")
  19. print("模型加载成功")
  20. embedding_manager.set_model(model)
  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()