Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

基于mlflow的模型服务

构建mlflow server模型

python server/model_server.py --experiment_name "textmatch" --version_name "001" --model_file "textmodel"

启动服务

mlflow models serve -m /Users/qudian/Desktop/TextMatch/textmodel/ -h 0.0.0.0 -w 3 -p 5000 --no-conda

测试: python post_data.py

import requests
import pandas as pd
import json
import time 


for i in range(100):
    # 构造需要进行推断的数据
    newJson = '{"text":"我在九寨沟,很喜欢"}'
    # 指定ip, 端口
    url = "http://127.0.0.1:5000/invocations"
    # 传递的参数需要从dataframe转化为json格式
    json_data = json.loads( newJson )
    model_input = pd.DataFrame([json_data])
    req_data = model_input.to_json(orient='split')
    headers = {'content-type': 'application/json; format=pandas-split'}
    # 使用POST方式调用REST api
    start_time = time.time()
    respond = requests.request("POST", url, data=req_data, headers=headers) 
    print ("time>>>>>>>", time.time() - start_time)
    print ( "respond>>", respond )
    # 获取返回值
    print (respond.json()) 

'''
time>>>>>>> 0.00647282600402832
respond>> <Response [200]>
{'bow': [['0', 0.27735009448572867], ['1', 0.5303300779349595], ['2', 0.8660253835771797], ['3', 0.0]], 'tfidf': [['0', 0.22011588892661677], ['1', 0.4647626270035471], ['2', 0.8749224658050323], ['3', 0.0]], 'ngram_tfidf': [['0', 0.0], ['1', 0.14798919161252086], ['2', 0.9999998300000288], ['3', 0.0]]}
'''