curl - 使用 curl 将 post 请求发送到 mlflow api 到多条记录
问题描述
我提供了一个 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
它正在得分。但是,对于我的特定项目,用于评分的 rest api 的输入将始终是 dataframe/csv 格式的多个记录,而不是单个记录。有人可以指出我如何实现这一目标吗?
解决方案
这有效:
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}')
推荐阅读
- java - 如何在 UML 类图中表示定义枚举的类?
- java - 使用服务单击列表视图时如何在 exoplayer 上播放特定音频?
- continuous-integration - 使用 CircleCI 在 scp 上部署 dist 文件夹时部署作业卡住
- python - TKinter:在 Python 类中获取变量并将其发送给另一个
- node.js - mongoDB 中的非重复排列可能的查询?_ 猫鼬 nodejs
- sql-server - 将数据库表中的数据存储在全局变量中以随时使用
- html - 调用新数据时强制聊天样式滚动到元素底部
- javascript - 是否可以根据 Angular 中的对象属性更改元素样式?
- javascript - 为什么 jQuery mobile 上的弹出式滚动不起作用?
- python - Django完整性错误NOT NULL约束