Skip to content

Instantly share code, notes, and snippets.

@ghotz
Created August 13, 2018 11:32
Show Gist options
  • Save ghotz/e97f4a9117b537a18e57216750464433 to your computer and use it in GitHub Desktop.
Save ghotz/e97f4a9117b537a18e57216750464433 to your computer and use it in GitHub Desktop.
Analyze local image by URL with Clarifai API in PowerShell
# Analyze local image by URL with Clarifai API in PowerShell
$ClarifaiAPIURL = "https://api.clarifai.com/v2";
$ClarifaiAPIKey = "YOUR_KEY_GOES_HERE";
$ClarifaiAPIPredictTemplateURL = ($ClarifaiAPIURL + "/models/{0}/outputs")
$ImageFilename = "C:\Temp\cognitive\20180805-143608-GH01C12-S00.jpg";
$PredictInputs =
@{
inputs = @(@{
data = @{
image = @{
base64 = ([Convert]::ToBase64String([IO.File]::ReadAllBytes($ImageFilename)))
}
}
})
};
$JSonPredictInputs = ConvertTo-Json $PredictInputs -Depth 4
$ModelId = "aaa03c23b3724a16a56b629203edc62c"; # general-v1.3 model
$Response = Invoke-WebRequest `
-Uri ($ClarifaiAPIPredictTemplateURL -f $ModelId) `
-Headers @{'Authorization' = ("Key " + $ClarifaiAPIKey)} `
-Body $JSonPredictInputs `
-ContentType "application/json" `
-Method "Post" `
-ErrorAction Stop `
-UseBasicParsing;
$Response.Content | Out-File ([System.IO.Path]::ChangeExtension($ImageFilename, "predict.$ModelId.json")) -Encoding UTF8;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment