Download test_inference.sh from torinittechnologies/learningstudio-callout-wrapper: direct link, hf CLI and curl.
- Browser
- Download file 1.12 kB
-
https://huggingface.co/torinittechnologies/learningstudio-callout-wrapper/resolve/main/test_inference.sh
- Command line
-
hf download hf://torinittechnologies/learningstudio-callout-wrapper/test_inference.sh
-
curl -L -o test_inference.sh https://huggingface.co/torinittechnologies/learningstudio-callout-wrapper/resolve/main/test_inference.sh
1.12 kB
| # Test the HuggingFace Inference Endpoint with a local image file | |
| # Usage: ./test_inference.sh <image_file> | |
| set -e | |
| if [ -z "$1" ]; then | |
| echo "Usage: $0 <image_file>" | |
| exit 1 | |
| fi | |
| IMAGE_FILE="$1" | |
| if [ ! -f "$IMAGE_FILE" ]; then | |
| echo "Error: File not found: $IMAGE_FILE" | |
| exit 1 | |
| fi | |
| # Required environment variables | |
| if [ -z "$HF_ENDPOINT" ]; then | |
| echo "Error: HF_ENDPOINT not set" | |
| echo "Export it first: export HF_ENDPOINT=https://xxx.endpoints.huggingface.cloud" | |
| exit 1 | |
| fi | |
| if [ -z "$HF_TOKEN" ]; then | |
| echo "Error: HF_TOKEN not set" | |
| echo "Export it first: export HF_TOKEN=hf_xxx" | |
| exit 1 | |
| fi | |
| # Convert image to base64 and create JSON payload in temp file | |
| echo "Converting $IMAGE_FILE to base64..." | |
| TEMP_FILE=$(mktemp) | |
| trap "rm -f $TEMP_FILE" EXIT | |
| printf '{"inputs": "' > "$TEMP_FILE" | |
| base64 -i "$IMAGE_FILE" | tr -d '\n' >> "$TEMP_FILE" | |
| printf '"}' >> "$TEMP_FILE" | |
| echo "Sending request to $HF_ENDPOINT..." | |
| curl -s -X POST "$HF_ENDPOINT" \ | |
| -H "Authorization: Bearer $HF_TOKEN" \ | |
| -H "Content-Type: application/json" \ | |
| -d @"$TEMP_FILE" | python3 -m json.tool | |