我想使用 Nyckel 机器学习服务的 Django 后端在我的 Web 应用程序中集成机器学习系统?

i want to integrate an Machine Learning system in my web app using Django Back-end from Nyckel Machine Learning Service?

我将请求发送给 Nyckel 服务并以文本形式返回响应,但我收到的响应格式无效 我正在研究实现图像分类:

我需要得到的结果取决于我通过 POST Nyckel 服务请求发送的图像:

{

"labelName": "harissa",

"labelId": "label_684pbumtvbzp3k9q",

“信心”:0.76

}

@api_view(['POST','GET'])

def addProductByNyckel(请求):

data = request.data


image = data['image']
url = 'https://www.nyckel.com/v1/functions/7aaigszss2ejx7t8/invoke/?format=json'
header = {
'Content-type': 'application/json', 'Accept': 'text/plain'
}

urlimg = 'http://127.0.0.1:8000/media/images/chamia_2lJVXBC.jpg'


img = requests.get(urlimg,params=request.GET)
m = img.content

result = requests.post(url,m, headers=header)
dict = result.json() 

labelName= dict.get("labelName"),
labelId = dict.get("labelId"),
confidence = dict.get("confidence")

return Response(dict )
`

错误信息是:

**{

"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",


"title": "One or more validation errors occurred.",


"status": 400,


"traceId": "00-983824a0cb2b204855f4387cf92f2dca-780a95630f9dc3d6-00",


"errors": {

    "$": [

        "'0x89' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0."

    ],


    "input": [

        "The input field is required."

    ]

}

}**

根据 nickle 文档,您需要通过多部分请求发送它。

这里是示例工作请求

import requests
url = 'https://www.nyckel.com/v1/functions/7aaigszss2ejx7t8/invoke/?format=json'
file = open('/tmp/sharukh.jpeg', 'rb') # it has to be file content
result = requests.post(url, files={'data': file}) # posting multipart payload
dict = result.json()
print(dict, result.status_code)