123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- """
- @author: luojunhui
- """
- from quart import Blueprint, jsonify, request
- from .accountArticleRank import AccountArticleRank
- from .nlpServer import NLPServer
- from .articleDBServer import ArticleSpider
- from .accountServer import AccountServer
- from .word_2_vec import process_text
- from applications.articleTools import ArticleDBTools
- def AlgRoutes(mysql_client, model, word_vec_model, embedding_manager):
- """
- ALG ROUTES
- :return:
- """
- blueprint = Blueprint("LongArticlesAlgServer", __name__)
- @blueprint.route("/embed", methods=["POST"])
- async def embed():
- """
- 测试词向量模型
- :return:
- """
- params = await request.get_json()
- text = params["text"]
- words, vectors = process_text(word_vec_model, text)
- res = {
- "text": text,
- "tokens": words,
- "embeddings": [vec.tolist() for vec in vectors]
- }
- return jsonify(res)
- @blueprint.route("/healthCheck")
- def helloFuture():
- """
- 测试服务连通性
- :return:
- """
- response = {"msg": "Hello, World! Hello, Future"}
- return jsonify(response)
- @blueprint.route("/articleRank", methods=["POST"])
- async def articleRankRoute():
- """
- 文章排序接口
- :return:
- """
- params = await request.get_json()
- AAR = AccountArticleRank(params, mysql_client=mysql_client)
- response = await AAR.deal()
- # print(response)
- return jsonify(response)
- @blueprint.route("/nlp", methods=["POST"])
- async def nlper():
- """
- nlper ma
- :return:
- """
- params = await request.get_json()
- nlpS = NLPServer(params=params, model=model, embedding_manager=embedding_manager)
- response = nlpS.deal()
- return jsonify(response)
- @blueprint.route("/score_list", methods=["POST"])
- async def article_account():
- """
- 公众号文章功能等接口
- :return:
- """
- params = await request.get_json()
- AS = AccountServer(mysql_client=mysql_client, params=params)
- response = await AS.deal()
- return jsonify(response)
- @blueprint.route("/title_list", methods=["POST"])
- async def accountTitle():
- """
- 获取账号的标题list
- :return:
- """
- params = await request.get_json()
- print(params)
- ADBT = ArticleDBTools(mysql_client=mysql_client)
- responseDF = await ADBT.getArticleByFilter(
- account_name=params['account_name'],
- index_list=params['index_list'],
- min_time=params['min_time'],
- max_time=params['max_time'],
- msg_type=params['msg_type'],
- )
- title_list = responseDF['title']
- response = {"title_list": title_list.values.tolist()}
- return jsonify(response)
- @blueprint.route("/article_crawler", methods=["POST"])
- async def articleMysql():
- """
- 长文数据库相关接口
- :return:
- """
- params = await request.get_json()
- ADB = ArticleSpider(params=params, mysql_client=mysql_client)
- response = await ADB.deal()
- return jsonify(response)
- return blueprint
|