d11j

VisionAPI safe search detection

Jun 15th, 2021 (edited)
722
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.78 KB | None | 0 0
  1. #!/bin/bash
  2. if [ $# != 1 ]; then
  3.     echo "Invalid argument"
  4.     exit 1
  5. fi
  6. uri=$1
  7. echo Image uri is ${uri}
  8. scode=$(curl "${uri}" -o /dev/null -w '%{http_code}\n' -s)
  9. if [ $scode != 200 ]; then
  10.     echo HTTP status is ${scode}, abort.
  11.     exit 1
  12. fi
  13. sed -e "s|@@URL_HERE@@|${uri}|" << EOF | curl -X POST -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) -H "Content-Type: application/json; charset=utf-8" -d @- https://vision.googleapis.com/v1/images:annotate
  14. {
  15.   "requests": [
  16.     {
  17.       "image": {
  18.     "source": {
  19.       "imageUri": "@@URL_HERE@@"
  20.     }
  21.       },
  22.       "features": [
  23.     {
  24.       "type": "SAFE_SEARCH_DETECTION"
  25.     }
  26.       ]
  27.     }
  28.   ]
  29. }
  30. EOF
  31. echo ?:UNKNOWN, 1:VERY_UNLIKELY, 2:UNLIKELY, 3:POSSIBLE, 4LIKELY, 5:VERY_LIKELY
Add Comment
Please, Sign In to add comment