#!/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