我已经创建了我的表单识别器 AI,对其进行了训练,并收到了 modelID,但是当我实际在 Powershell 中实现它时,它会出错,告诉我它无法读取文件,所以我怀疑它与我正在发送的文件有关。
这是针对表单识别器 2.0 的,有什么建议吗?
cls
$aiFormRecognizerKey = '{apiKey}'
$aiFormRecognizerEndPoint = 'https://{Url}.cognitiveservices.azure.com/'
$aiModelToUse = 'f11f43a7-6207-4dc9-9e8a-fc58677047f1'
$headers = @{
"Ocp-Apim-Subscription-Key" = $aiFormRecognizerKey
"Content-Type" = "application/pdf"
}
$FormFields = @{
"form-data" = Get-Item C:\temp\test3.pdf
"type" = "application/pdf"
}
$analyzedDocumentLocation = (Invoke-WebRequest ($aiFormRecognizerEndPoint + 'formrecognizer/v2.0- preview/custom/models/' + $aiModelToUse + '/analyze' ) -Method "POST" -Headers ($headers) -Body $FormFields ).Headers.'Operation-Location'
$analyzedDocumentLocation
$uriTest = 'https://{url}.cognitiveservices.azure.com/formrecognizer/v2.0- preview/custom/models/5b4cb7c4-406f-400d-b53e-7d50fecd4a1d/analyzeresults/b07b863e-0aa5-4e1d-9a64- 73eb18c1f793'
Invoke-WebRequest -uri $uriTest -Method "GET" -Headers ($headers)
编辑:
这是像我这样好奇的人的解决方案:
cls
$aiFormRecognizerKey = '{Key}'
$aiFormRecognizerEndPoint =
'https://{MyEndPoint}.cognitiveservices.azure.com/'
$aiModelToUse = '{TrainedModelId}'
$headers = @{
"Ocp-Apim-Subscription-Key" = $aiFormRecognizerKey
}
$analyzedDocumentLocation = (Invoke-WebRequest -InFile C:\temp\test1.pdf -
ContentType "application/pdf" -uri ($aiFormRecognizerEndPoint +
'formrecognizer/v2.0-preview/custom/models/' + $aiModelToUse + '/analyze' )
-Method "POST" -Headers ($headers)).Headers.'Operation-Location'
$analyzedDocumentLocation
$uriTest = $analyzedDocumentLocation[0]
$FileStream.Close()
Start-Sleep -s 10
(Invoke-WebRequest -uri $uriTest -Method "GET" -Headers ($headers)).Content