alg_app.py 788 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. """
  2. @author: luojunhui
  3. """
  4. from quart import Quart
  5. from routes import AlgRoutes
  6. from applications import AsyncMySQLClient
  7. from applications.algorthims import titleSimilarity
  8. app = Quart(__name__)
  9. AsyncMySQL = AsyncMySQLClient(app)
  10. app_routes = AlgRoutes(AsyncMySQL)
  11. app.register_blueprint(app_routes)
  12. @app.before_serving
  13. async def init_db():
  14. """
  15. 初始化
  16. :return:
  17. """
  18. await AsyncMySQL.init_pool()
  19. @app.before_serving
  20. def init_bert_model():
  21. """
  22. 初始化bert模型
  23. :return:
  24. """
  25. Ts = titleSimilarity()
  26. Ts.loading_model()
  27. print("Bert Model has already loaded")
  28. @app.after_serving
  29. async def close_db():
  30. """
  31. 关闭连接
  32. :return:
  33. """
  34. await AsyncMySQL.close_pool()
  35. if __name__ == '__main__':
  36. app.run(debug=True)