__init__.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. """
  2. @author: luojunhui
  3. """
  4. from quart import Blueprint, jsonify, request
  5. from .accountArticleRank import AccountArticleRank
  6. from .nlpServer import NLPServer
  7. from .articleDBServer import ArticleSpider
  8. from .accountServer import AccountServer
  9. from .word_2_vec import process_text
  10. from applications.articleTools import ArticleDBTools
  11. def AlgRoutes(mysql_client, model, word_vec_model, embedding_manager):
  12. """
  13. ALG ROUTES
  14. :return:
  15. """
  16. blueprint = Blueprint("LongArticlesAlgServer", __name__)
  17. @blueprint.route("/embed", methods=["POST"])
  18. async def embed():
  19. """
  20. 测试词向量模型
  21. :return:
  22. """
  23. params = await request.get_json()
  24. text = params["text"]
  25. words, vectors = process_text(word_vec_model, text)
  26. res = {
  27. "text": text,
  28. "tokens": words,
  29. "embeddings": [vec.tolist() for vec in vectors]
  30. }
  31. return jsonify(res)
  32. @blueprint.route("/healthCheck")
  33. def helloFuture():
  34. """
  35. 测试服务连通性
  36. :return:
  37. """
  38. response = {"msg": "Hello, World! Hello, Future"}
  39. return jsonify(response)
  40. @blueprint.route("/articleRank", methods=["POST"])
  41. async def articleRankRoute():
  42. """
  43. 文章排序接口
  44. :return:
  45. """
  46. params = await request.get_json()
  47. AAR = AccountArticleRank(params, mysql_client=mysql_client)
  48. response = await AAR.deal()
  49. # print(response)
  50. return jsonify(response)
  51. @blueprint.route("/nlp", methods=["POST"])
  52. async def nlper():
  53. """
  54. nlper ma
  55. :return:
  56. """
  57. params = await request.get_json()
  58. nlpS = NLPServer(params=params, model=model, embedding_manager=embedding_manager)
  59. response = nlpS.deal()
  60. return jsonify(response)
  61. @blueprint.route("/score_list", methods=["POST"])
  62. async def article_account():
  63. """
  64. 公众号文章功能等接口
  65. :return:
  66. """
  67. params = await request.get_json()
  68. AS = AccountServer(mysql_client=mysql_client, params=params)
  69. response = await AS.deal()
  70. return jsonify(response)
  71. @blueprint.route("/title_list", methods=["POST"])
  72. async def accountTitle():
  73. """
  74. 获取账号的标题list
  75. :return:
  76. """
  77. params = await request.get_json()
  78. print(params)
  79. ADBT = ArticleDBTools(mysql_client=mysql_client)
  80. responseDF = await ADBT.getArticleByFilter(
  81. account_name=params['account_name'],
  82. index_list=params['index_list'],
  83. min_time=params['min_time'],
  84. max_time=params['max_time'],
  85. msg_type=params['msg_type'],
  86. )
  87. title_list = responseDF['title']
  88. response = {"title_list": title_list.values.tolist()}
  89. return jsonify(response)
  90. @blueprint.route("/article_crawler", methods=["POST"])
  91. async def articleMysql():
  92. """
  93. 长文数据库相关接口
  94. :return:
  95. """
  96. params = await request.get_json()
  97. ADB = ArticleSpider(params=params, mysql_client=mysql_client)
  98. response = await ADB.deal()
  99. return jsonify(response)
  100. return blueprint