File size: 1,122 Bytes
e77552b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash

# 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