使用curl-to-mlflow api向多个记录发送post请求

使用curl-to-mlflow api向多个记录发送post请求,curl,post,deployment,mlflow,serving,Curl,Post,Deployment,Mlflow,Serving,我提供了mlflow模型,并以以下格式发送POST请求: curl -X POST -H "Content-Type:application/json; format=pandas-split" --data '{"columns":["alcohol", "chlorides", "citric acid", "density", "fixed acidity&

我提供了mlflow模型,并以以下格式发送POST请求:

curl -X POST -H "Content-Type:application/json; format=pandas-split" 
--data '{"columns":["alcohol", "chlorides", "citric acid", "density", 
"fixed acidity", "free sulfur dioxide", "pH", "residual sugar", "sulphates", 
"total sulfur dioxide", "volatile acidity"],"data":[[12.8, 0.029, 0.48, 0.98, 
6.2, 29, 3.33, 1.2, 0.39, 75, 0.66]]}' 
http://127.0.0.1:1234/invocations
它正在得分。但是,对于我的特定项目,RESTAPI的评分输入将始终是dataframe/csv格式的多条记录,而不是一条记录。有人能告诉我如何做到这一点吗

{
    "columns": [
        "alcohol",
        "chlorides",
        "citric acid",
        "density",
        "fixed acidity",
        "free sulfur dioxide",
        "pH",
        "residual sugar",
        "sulphates",
        "total sulfur dioxide",
        "volatile acidity"
    ],
    "index": [
        0,
        1
    ],
    "data": [
        [
            12.8,
            0.029,
            0.48,
            0.98,
            6.2,
            29.0,
            3.33,
            1.2,
            0.39,
            75.0,
            0.66
        ],
        [
            12.8,
            0.029,
            0.48,
            0.98,
            6.2,
            29.0,
            3.33,
            1.2,
            0.39,
            75.0,
            0.66
        ]
    ]
}
要生成json,请使用熊猫:

import pandas as pd

columns = ["alcohol", "chlorides", "citric acid", "density", 
"fixed acidity", "free sulfur dioxide", "pH", "residual sugar", "sulphates", 
"total sulfur dioxide", "volatile acidity"]
data = [[12.8, 0.029, 0.48, 0.98, 
6.2, 29, 3.33, 1.2, 0.39, 75, 0.66], [12.8, 0.029, 0.48, 0.98, 
6.2, 29, 3.33, 1.2, 0.39, 75, 0.66]]

df = pd.DataFrame(data, columns=columns)
json = df.to_json(orient="split")
print(json)
这起到了作用:

import requests
host = 'localhost'
port = '8001'
url = f'http://{host}:{port}/invocations'
headers = {'Content-Type': 'application/json',}
http_data = test_df.to_json(orient='split')
r = requests.post(url=url, headers=headers, data=http_data)
print(f'Predictions: {r.text}')