Spaces:
Paused
Paused
File size: 4,221 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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
#!/bin/bash
# Dots.OCR API Test Runner
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
# Default values
API_URL="http://localhost:7860"
TIMEOUT=30
VERBOSE=false
ROI=""
ENVIRONMENT="local"
# Function to print colored output
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Function to show usage
show_usage() {
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " -u, --url URL API base URL (default: http://localhost:7860)"
echo " -e, --env ENV Environment: local, staging, production (default: local)"
echo " -t, --timeout SECONDS Request timeout (default: 30)"
echo " -r, --roi JSON ROI coordinates as JSON string"
echo " -v, --verbose Enable verbose output"
echo " -q, --quick Run quick test only"
echo " -h, --help Show this help message"
echo ""
echo "Examples:"
echo " $0 # Basic test (local)"
echo " $0 -e production # Test production API"
echo " $0 -e staging # Test staging API"
echo " $0 -u https://api.example.com # Test custom API URL"
echo " $0 -r '{\"x1\":0.1,\"y1\":0.1,\"x2\":0.9,\"y2\":0.9}' # Test with ROI"
echo " $0 -v -t 60 # Verbose with 60s timeout"
echo " $0 -q # Quick test only"
}
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
-u|--url)
API_URL="$2"
shift 2
;;
-e|--env)
ENVIRONMENT="$2"
shift 2
;;
-t|--timeout)
TIMEOUT="$2"
shift 2
;;
-r|--roi)
ROI="$2"
shift 2
;;
-v|--verbose)
VERBOSE=true
shift
;;
-q|--quick)
QUICK=true
shift
;;
-h|--help)
show_usage
exit 0
;;
*)
print_error "Unknown option: $1"
show_usage
exit 1
;;
esac
done
# Set API URL based on environment if not explicitly provided
if [ "$API_URL" = "http://localhost:7860" ] && [ "$ENVIRONMENT" != "local" ]; then
case $ENVIRONMENT in
"staging")
API_URL="https://algoryn-dots-ocr-idcard-staging.hf.space"
;;
"production")
API_URL="https://algoryn-dots-ocr-idcard.hf.space"
;;
*)
print_error "Unknown environment: $ENVIRONMENT. Use: local, staging, production"
exit 1
;;
esac
fi
# Check if Python is available
if ! command -v python3 &> /dev/null; then
print_error "Python 3 is required but not installed"
exit 1
fi
# Check if test images exist
if [ ! -f "tom_id_card_front.jpg" ] || [ ! -f "tom_id_card_back.jpg" ]; then
print_error "Test images not found. Please ensure tom_id_card_front.jpg and tom_id_card_back.jpg are in the scripts directory"
exit 1
fi
print_status "Starting Dots.OCR API Tests"
print_status "Environment: $ENVIRONMENT"
print_status "API URL: $API_URL"
print_status "Timeout: $TIMEOUT seconds"
# Run quick test if requested
if [ "$QUICK" = true ]; then
print_status "Running quick test..."
if python3 quick_test.py "$API_URL"; then
print_success "Quick test passed"
exit 0
else
print_error "Quick test failed"
exit 1
fi
fi
# Build test command
TEST_CMD="python3 test_api_endpoint.py --url $API_URL --timeout $TIMEOUT"
if [ "$VERBOSE" = true ]; then
TEST_CMD="$TEST_CMD --verbose"
fi
if [ -n "$ROI" ]; then
TEST_CMD="$TEST_CMD --roi '$ROI'"
fi
# Run comprehensive test
print_status "Running comprehensive API test..."
if eval $TEST_CMD; then
print_success "All tests passed successfully!"
exit 0
else
print_error "Tests failed"
exit 1
fi
|