#!/bin/bash # Test script for Hugging Face Dots-OCR Space API using curl HF_SPACE_URL="https://algoryn-dots-ocr-idcard.hf.space" echo "🚀 Testing Hugging Face Dots-OCR Space API" echo "==========================================" # Test 1: Health check echo "" echo "1️⃣ Testing health check..." curl -s "${HF_SPACE_URL}/health" | jq '.' 2>/dev/null || curl -s "${HF_SPACE_URL}/health" # Test 2: OCR extraction (if demo image exists) DEMO_IMAGE="data/demo/tom_id_card_front.jpg" if [ -f "$DEMO_IMAGE" ]; then echo "" echo "2️⃣ Testing OCR extraction with $DEMO_IMAGE..." curl -X POST "${HF_SPACE_URL}/v1/id/ocr" \ -F "file=@$DEMO_IMAGE" | jq '.' 2>/dev/null || echo "Response received (install jq for pretty JSON)" # Test 3: OCR with ROI (top half of image) echo "" echo "3️⃣ Testing OCR with ROI (top half)..." curl -X POST "${HF_SPACE_URL}/v1/id/ocr" \ -F "file=@$DEMO_IMAGE" \ -F 'roi={"x1": 0.0, "y1": 0.0, "x2": 1.0, "y2": 0.5}' | jq '.' 2>/dev/null || echo "Response received (install jq for pretty JSON)" # Test 4: OCR with ROI (center region) echo "" echo "4️⃣ Testing OCR with ROI (center region)..." curl -X POST "${HF_SPACE_URL}/v1/id/ocr" \ -F "file=@$DEMO_IMAGE" \ -F 'roi={"x1": 0.25, "y1": 0.25, "x2": 0.75, "y2": 0.75}' | jq '.' 2>/dev/null || echo "Response received (install jq for pretty JSON)" else echo "" echo "2️⃣ No demo image found at $DEMO_IMAGE" echo "💡 Place a test image in the data/demo/ directory" fi echo "" echo "🎉 Testing complete!" echo "" echo "💡 To test with your own files:" echo " curl -X POST \"${HF_SPACE_URL}/v1/id/ocr\" -F \"file=@your_image.jpg\"" echo "" echo "💡 To test with ROI:" echo " curl -X POST \"${HF_SPACE_URL}/v1/id/ocr\" -F \"file=@your_image.jpg\" -F 'roi={\"x1\": 0.0, \"y1\": 0.0, \"x2\": 0.5, \"y2\": 0.5}'" echo "" echo "💡 Available ROI examples:" echo " Full image: no roi parameter" echo " Top half: {\"x1\": 0.0, \"y1\": 0.0, \"x2\": 1.0, \"y2\": 0.5}" echo " Bottom half: {\"x1\": 0.0, \"y1\": 0.5, \"x2\": 1.0, \"y2\": 1.0}" echo " Center: {\"x1\": 0.25, \"y1\": 0.25, \"x2\": 0.75, \"y2\": 0.75}" echo " Left side: {\"x1\": 0.0, \"y1\": 0.0, \"x2\": 0.5, \"y2\": 1.0}" echo " Right side: {\"x1\": 0.5, \"y1\": 0.0, \"x2\": 1.0, \"y2\": 1.0}"