File size: 1,953 Bytes
34c6057
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env bash
# Quick tester for Dots.OCR debug mode using curl.
#
# Usage examples:
#   scripts/test_debug_ocr.sh -u http://localhost:7860 -f scripts/tom_id_card_front.jpg -d
#   scripts/test_debug_ocr.sh -u https://<your-hf-space>.hf.space -f scripts/tom_id_card_front.jpg -d -r '{"x1":0,"y1":0,"x2":1,"y2":0.5}'
#
# Notes:
# - The `debug` form field enables per-request debug logging on the server.
# - You can also set env DOTS_OCR_DEBUG=1 on the server to enable globally.

set -euo pipefail

API_URL="http://localhost:7860"
FILE_PATH=""
ROI_JSON=""
ENABLE_DEBUG=false

usage() {
  echo "Usage: $0 -u <api_url> -f <image_or_pdf> [-d] [-r '<roi-json>']" >&2
  echo "  -u  API base URL (default: ${API_URL})" >&2
  echo "  -f  Path to image/PDF file to upload" >&2
  echo "  -d  Enable per-request debug logging (adds -F debug=true)" >&2
  echo "  -r  ROI JSON string, e.g. '{\"x1\":0,\"y1\":0,\"x2\":1,\"y2\":0.5}'" >&2
  exit 1
}

while getopts ":u:f:r:d" opt; do
  case ${opt} in
    u) API_URL="$OPTARG" ;;
    f) FILE_PATH="$OPTARG" ;;
    r) ROI_JSON="$OPTARG" ;;
    d) ENABLE_DEBUG=true ;;
    *) usage ;;
  esac
done

if [[ -z "$FILE_PATH" ]]; then
  echo "Error: file path is required." >&2
  usage
fi

if [[ ! -f "$FILE_PATH" ]]; then
  echo "Error: file not found: $FILE_PATH" >&2
  exit 2
fi

echo "🚀 Testing Dots.OCR API at $API_URL"
echo "File: $FILE_PATH"
if [[ -n "$ROI_JSON" ]]; then
  echo "ROI:  $ROI_JSON"
fi
echo "Debug: $ENABLE_DEBUG"

CURL_ARGS=(
  -sS -X POST "$API_URL/v1/id/ocr"
  -F "file=@$FILE_PATH"
)

if [[ -n "$ROI_JSON" ]]; then
  CURL_ARGS+=( -F "roi=$ROI_JSON" )
fi

if [[ "$ENABLE_DEBUG" == true ]]; then
  CURL_ARGS+=( -F "debug=true" )
fi

# Pretty-print with jq if available
if command -v jq >/dev/null 2>&1; then
  curl "${CURL_ARGS[@]}" | jq '.'
else
  echo "(Install jq for pretty JSON)"
  curl "${CURL_ARGS[@]}"
fi

echo ""
echo "Done. Check server logs for detailed debug output when enabled."