gpt4 book ai didi

python - 将批量数据发送到 Azure ML 端点

转载 作者:行者123 更新时间:2023-11-30 08:47:51 25 4
gpt4 key购买 nike

我有一个 Azure ML 端点,用于在我以 json 格式提供数据时获得评分。

import requests
import json

# URL for the web service
scoring_uri = 'http://107a119d-9c23-4792-b5db-065e9d3af1e6.eastus.azurecontainer.io/score'

# If the service is authenticated, set the key or token
key = '##########################'


data = {"data":
[{'Associate_Gender': 'Male', 'Associate_Age': 20, 'Education': 'Under Graduate', 'Source_Hiring': 'Internal Movement', 'Count_of_Incoming_Calls_6_month': None, 'Count_of_Incoming_Calls_6_month_bucket': 'Greater than equal to 0 and less than 4', 'Internal_Quality_IQ_Score_Last_6_Months': '93%', 'Internal_Quality_IQ_Score_Last_6_Months_Bucket': 'Greater than 75%', 'Associate_Tenure_Floor_Bucket': 'Greater than 0 and less than 90', 'Current_Call_Repeat_Yes_No': False, 'Historical_CSAT_score': 'Greater than equal to 7 and less than 9', 'Customer_Age': 54, 'Customer_Age_Bucket': 'Greater than equal to 46', 'Network_Region_Originating_Call': 'East London', 'Length_of_Relationship_with_Customer': 266, 'Length_of_Relationship_with_Customer_bucket': 'Greater than 90', 'Call_Reason_Type_L1': 'Voice', 'Call_Reason_Type_L2': 'Prepaid', 'Call_Reason_Type_L3': 'Request for Reversal Provisioning', 'Number_of_VAS_services_active': 6, 'Customer_Category': 'Mercury', 'Customer_monthly_ARPU_GBP_Bucket': 'More than 30', 'Customer_Location': 'Houslow'}]
}
# Convert to JSON string
input_data = json.dumps(data)

# Set the content type
headers = {'Content-Type': 'application/json'}
# If authentication is enabled, set the authorization header
headers['Authorization'] = f'Bearer {key}'

# Make the request and display the response
resp = requests.post(scoring_uri, input_data, headers=headers)
print(resp.text)

如何批量发送文件中的输入数据并获取输出。或者发送大量数据在端点上进行评分是否不可行?
也欢迎任何有关在 azure 上评分的替代建议。

最佳答案

假设您有一个名为 json_data 的文件夹,其中存储了所有 json 文件,那么您将打开这些文件并将它们发布到您的端点,如下所示:

import requests
import json
import os
import glob

your_uri = 'https://jsonplaceholder.typicode.com/'
folder_path = './json_data'

for filename in glob.glob(os.path.join(folder_path, '*.json')):
with open(filename, 'r') as f:
json_input_data = json.load(f)
resp = requests.post(your_uri, json_input_data)
print(resp)

要使用 jsonplaceholder.typicode.com 展示成功的 http 响应 201,您必须在 python 文件的同一目录中创建一个文件夹并将其命名为 json_data,然后在文件夹内创建一些 json 文件并将一些数据粘贴到文件中,例如:

文件1.json:

{
"title": "some title name 1",
"body": "some body content 1"
}

文件2.json:

{
"title": "some title name 2",
"body": "some body content 2"
}

等等

您可以轻松重写它并使用您自己的 uri、 key 、 header 等。

关于python - 将批量数据发送到 Azure ML 端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59711742/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com