罗俊辉 il y a 1 an
Parent
commit
144a472598

+ 3 - 2
README.md

@@ -1,3 +1,4 @@
-# lightgbm_score
+# 基于 Quart 的 lightgbm_score 评分服务
+
+lightgbm 模型预测服务
 
-lightgbm 模型预测服务

+ 31 - 0
applications/functions.py

@@ -0,0 +1,31 @@
+"""
+@author: luojunhui
+"""
+import asyncio
+
+
+from .model_init import models
+
+
+async def process_data(params):
+    """
+    执行结果
+    :param params:
+    :return:
+    """
+    print("正在处理")
+    flag = params['version']
+    if flag == "v1":
+        model = models.model_v1
+    elif flag == "v2":
+        model = models.model_v2
+    else:
+        return
+    features = params['features']
+    prediction = model.predict([features])
+    print("处理完成")
+    return {'prediction': prediction.tolist()}
+
+
+
+

+ 4 - 0
applications/log.py

@@ -0,0 +1,4 @@
+"""
+Aliyun Log Module
+@author: luojunhui
+"""

+ 27 - 0
applications/model_init.py

@@ -0,0 +1,27 @@
+"""
+@author: luojunhui
+"""
+import json
+import asyncio
+import lightgbm as lgb
+
+
+class Models(object):
+    """
+    LightGBM Models
+    """
+
+    def __init__(self):
+        """
+        在项目启动的时候加载好所有的模型
+        :return:
+        """
+        print("正在加载模型")
+        self.model_v1 = lgb.Booster(model_file="/root/lightgbm_score/models/lightgbm_0409_all_tags.bin")
+        print("模型 1 加载完成......")
+        self.model_v2 = lgb.Booster(model_file="/root/lightgbm_score/models/lightgbm_0409_spider.bin")
+        print("模型 2 加载完成......")
+        print("所有模型加载完成")
+
+
+models = Models()

+ 28 - 0
applications/routes.py

@@ -0,0 +1,28 @@
+"""
+@author: luojunhui
+"""
+from quart import Blueprint, jsonify, request
+from applications.functions import process_data
+
+
+video_score_blueprint = Blueprint('light_gbm_score', __name__)
+
+
+@video_score_blueprint.route('/hello')
+async def hello():
+    """
+    Hello World Test
+    :return:
+    """
+    return jsonify({'message': 'Hello, World!'})
+
+
+@video_score_blueprint.route('/lightgbm_score', methods=['POST'])
+async def post_data():
+    """
+    请求接口代码
+    :return:
+    """
+    data = await request.get_json()
+    processed_data = await process_data(data)
+    return jsonify(processed_data)

+ 25 - 0
async_app.py

@@ -0,0 +1,25 @@
+"""
+@author: luojunhui
+"""
+from quart import Quart
+from applications.routes import video_score_blueprint
+from applications.model_init import Models
+
+# 初始化 App
+app = Quart(__name__)
+
+# 注册蓝图
+app.register_blueprint(video_score_blueprint)
+
+
+@app.before_serving
+async def before_serving():
+    """
+    在服务器正式开始接受请求之前加载模型
+    :return: None
+    """
+    Models()
+
+
+if __name__ == '__main__':
+    app.run(debug=True)

Fichier diff supprimé car celui-ci est trop grand
+ 8 - 0
models/lightgbm_0409_all_tags.bin


Fichier diff supprimé car celui-ci est trop grand
+ 8 - 0
models/lightgbm_0409_spider.bin


Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff