File size: 2,263 Bytes
211e423
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
# Production API Test using curl

set -e

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color

# Production API URL
API_URL="https://algoryn-dots-ocr-idcard.hf.space"

# Function to print colored output
print_status() {
    echo -e "${BLUE}[INFO]${NC} $1"
}

print_success() {
    echo -e "${GREEN}[SUCCESS]${NC} $1"
}

print_error() {
    echo -e "${RED}[ERROR]${NC} $1"
}

print_warning() {
    echo -e "${YELLOW}[WARNING]${NC} $1"
}

# Check if test image exists
if [ ! -f "tom_id_card_front.jpg" ]; then
    print_error "Test image not found: tom_id_card_front.jpg"
    exit 1
fi

print_status "Testing Production API at $API_URL"

# Health check
print_status "Checking API health..."
if curl -s -f "$API_URL/health" > /dev/null; then
    print_success "Health check passed"
else
    print_error "Health check failed"
    exit 1
fi

# Test OCR endpoint
print_status "Testing OCR endpoint with tom_id_card_front.jpg"

# Make the API request
response=$(curl -s -w "\n%{http_code}" -X POST \
    -F "file=@tom_id_card_front.jpg" \
    "$API_URL/v1/id/ocr")

# Split response and status code
http_code=$(echo "$response" | tail -n1)
response_body=$(echo "$response" | head -n -1)

if [ "$http_code" -eq 200 ]; then
    print_success "OCR request successful"
    
    # Parse and display results
    echo "$response_body" | jq -r '.request_id' | while read request_id; do
        echo "Request ID: $request_id"
    done
    
    echo "$response_body" | jq -r '.processing_time' | while read processing_time; do
        echo "Processing time: ${processing_time}s"
    done
    
    echo "$response_body" | jq -r '.detections | length' | while read detection_count; do
        echo "Detections: $detection_count"
    done
    
    # Show extracted fields
    echo "$response_body" | jq -r '.detections[0].extracted_fields | to_entries[] | select(.value != null) | "\(.key): \(.value.value) (confidence: \(.value.confidence))"' | while read field_info; do
        echo "  $field_info"
    done
    
    print_success "Production API test completed successfully!"
    
else
    print_error "OCR request failed with status code: $http_code"
    echo "Response: $response_body"
    exit 1
fi