Skip to content

Instantly share code, notes, and snippets.

@louisje
Last active May 13, 2016 06:54
Show Gist options
  • Save louisje/86a6c382b0a89db7f97d to your computer and use it in GitHub Desktop.
Save louisje/86a6c382b0a89db7f97d to your computer and use it in GitHub Desktop.
FROM ubuntu
RUN apt-get update
RUN apt-get install -y curl jq
WORKDIR /root
RUN curl -ksL https://gist.github.com/louisje/86a6c382b0a89db7f97d/raw/vision-adult.sh > vision-adult.sh
RUN chmod a+x vision-adult.sh
ENTRYPOINT [ "./vision-adult.sh" ]
CMD [ "--help" ]
#!/bin/bash
if test -z "$1" -o "$1" = "--help"; then
echo "Usage: vision.sh < image_url | file >"
exit 1
fi
if [[ "$1" == http* ]]; then
base64=$(curl -s -k "$1" | base64)
else
base64=$(base64 "$1")
fi
if test -z "${base64}"; then
echo "Invalid Url <-- $1"
exit 1
fi
input="{
\"requests\":[
{
\"image\":{
\"content\":\"${base64}\"
},
\"features\":[
{
\"type\":\"SAFE_SEARCH_DETECTION\"
}
]
}
]
}"
echo "$1 --> $(echo "${input}" \
| curl -X POST -k -s \
-H "Content-Length: ${#input}" \
-H "Content-Type: application/json" \
--data-binary @/dev/stdin \
"https://vision.googleapis.com/v1/images:annotate?key=AIzaSyDueOFzxeBGiJNgBmobtcy9zNBe-Y_LC2s" \
| jq -C '.responses | map(if .safeSearchAnnotation then .safeSearchAnnotation else {} end) | map(.adult) | .[]')"
FROM ubuntu
RUN apt-get update
RUN apt-get install -y curl jq
WORKDIR /root
RUN curl -ksL https://gist.github.com/louisje/86a6c382b0a89db7f97d/raw/vision-label.sh > vision-label.sh
RUN chmod a+x vision-label.sh
ENTRYPOINT [ "./vision-label.sh" ]
CMD [ "--help" ]
#!/bin/bash
if test -z "$1" -o "$1" = "--help"; then
echo "Usage: vision.sh < image_url | file >"
exit 1
fi
if [[ "$1" == http* ]]; then
base64=$(curl -s -k "$1" | base64)
else
base64=$(base64 "$1")
fi
if test -z "${base64}"; then
echo "Invalid Url <-- $1"
exit 1
fi
input="{
\"requests\":[
{
\"image\":{
\"content\":\"${base64}\"
},
\"features\":[
{
\"type\":\"LABEL_DETECTION\"
}
]
}
]
}"
echo "$1 --> $(echo "${input}" \
| curl -X POST -k -s \
-H "Content-Length: ${#input}" \
-H "Content-Type: application/json" \
--data-binary @/dev/stdin \
"https://vision.googleapis.com/v1/images:annotate?key=AIzaSyDueOFzxeBGiJNgBmobtcy9zNBe-Y_LC2s" \
| jq -c '.responses | map(if .labelAnnotations then .labelAnnotations else [] end) | .[] | map(.description)')"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment