algoryn/dots-ocr-idcard
0
1#!/usr/bin/env bash2# Quick tester for Dots.OCR debug mode using curl.3#4# Usage examples:5# scripts/test_debug_ocr.sh -u http://localhost:7860 -f scripts/tom_id_card_front.jpg -d6# 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}'7#8# Notes:9# - The `debug` form field enables per-request debug logging on the server.10# - You can also set env DOTS_OCR_DEBUG=1 on the server to enable globally.11 12set -euo pipefail13 14API_URL="http://localhost:7860"15FILE_PATH=""16ROI_JSON=""17ENABLE_DEBUG=false18 19usage() {20 echo "Usage: $0 -u <api_url> -f <image_or_pdf> [-d] [-r '<roi-json>']" >&221 echo " -u API base URL (default: ${API_URL})" >&222 echo " -f Path to image/PDF file to upload" >&223 echo " -d Enable per-request debug logging (adds -F debug=true)" >&224 echo " -r ROI JSON string, e.g. '{\"x1\":0,\"y1\":0,\"x2\":1,\"y2\":0.5}'" >&225 exit 126}27 28while getopts ":u:f:r:d" opt; do29 case ${opt} in30 u) API_URL="$OPTARG" ;;31 f) FILE_PATH="$OPTARG" ;;32 r) ROI_JSON="$OPTARG" ;;33 d) ENABLE_DEBUG=true ;;34 *) usage ;;35 esac36done37 38if [[ -z "$FILE_PATH" ]]; then39 echo "Error: file path is required." >&240 usage41fi42 43if [[ ! -f "$FILE_PATH" ]]; then44 echo "Error: file not found: $FILE_PATH" >&245 exit 246fi47 48echo "๐ Testing Dots.OCR API at $API_URL"49echo "File: $FILE_PATH"50if [[ -n "$ROI_JSON" ]]; then51 echo "ROI: $ROI_JSON"52fi53echo "Debug: $ENABLE_DEBUG"54 55CURL_ARGS=(56 -sS -X POST "$API_URL/v1/id/ocr"57 -F "file=@$FILE_PATH"58)59 60if [[ -n "$ROI_JSON" ]]; then61 CURL_ARGS+=( -F "roi=$ROI_JSON" )62fi63 64if [[ "$ENABLE_DEBUG" == true ]]; then65 CURL_ARGS+=( -F "debug=true" )66fi67 68# Pretty-print with jq if available69if command -v jq >/dev/null 2>&1; then70 curl "${CURL_ARGS[@]}" | jq '.'71else72 echo "(Install jq for pretty JSON)"73 curl "${CURL_ARGS[@]}"74fi75 76echo ""77echo "Done. Check server logs for detailed debug output when enabled."78 79 80 