CoolFace
Apppublic

algoryn/dots-ocr-idcard

sourceHugging Faceotherupdated 1y agoView on Hugging Face
0likes
run_tests.sh164 linesDownload Raw Back to scripts
1#!/bin/bash2# Dots.OCR API Test Runner3 4set -e5 6# Colors for output7RED='\033[0;31m'8GREEN='\033[0;32m'9YELLOW='\033[1;33m'10BLUE='\033[0;34m'11NC='\033[0m' # No Color12 13# Default values14API_URL="http://localhost:7860"15TIMEOUT=3016VERBOSE=false17ROI=""18ENVIRONMENT="local"19 20# Function to print colored output21print_status() {22    echo -e "${BLUE}[INFO]${NC} $1"23}24 25print_success() {26    echo -e "${GREEN}[SUCCESS]${NC} $1"27}28 29print_warning() {30    echo -e "${YELLOW}[WARNING]${NC} $1"31}32 33print_error() {34    echo -e "${RED}[ERROR]${NC} $1"35}36 37# Function to show usage38show_usage() {39    echo "Usage: $0 [OPTIONS]"40    echo ""41    echo "Options:"42    echo "  -u, --url URL          API base URL (default: http://localhost:7860)"43    echo "  -e, --env ENV          Environment: local, staging, production (default: local)"44    echo "  -t, --timeout SECONDS  Request timeout (default: 30)"45    echo "  -r, --roi JSON         ROI coordinates as JSON string"46    echo "  -v, --verbose          Enable verbose output"47    echo "  -q, --quick            Run quick test only"48    echo "  -h, --help             Show this help message"49    echo ""50    echo "Examples:"51    echo "  $0                                    # Basic test (local)"52    echo "  $0 -e production                     # Test production API"53    echo "  $0 -e staging                        # Test staging API"54    echo "  $0 -u https://api.example.com        # Test custom API URL"55    echo "  $0 -r '{\"x1\":0.1,\"y1\":0.1,\"x2\":0.9,\"y2\":0.9}'  # Test with ROI"56    echo "  $0 -v -t 60                          # Verbose with 60s timeout"57    echo "  $0 -q                                # Quick test only"58}59 60# Parse command line arguments61while [[ $# -gt 0 ]]; do62    case $1 in63        -u|--url)64            API_URL="$2"65            shift 266            ;;67        -e|--env)68            ENVIRONMENT="$2"69            shift 270            ;;71        -t|--timeout)72            TIMEOUT="$2"73            shift 274            ;;75        -r|--roi)76            ROI="$2"77            shift 278            ;;79        -v|--verbose)80            VERBOSE=true81            shift82            ;;83        -q|--quick)84            QUICK=true85            shift86            ;;87        -h|--help)88            show_usage89            exit 090            ;;91        *)92            print_error "Unknown option: $1"93            show_usage94            exit 195            ;;96    esac97done98 99# Set API URL based on environment if not explicitly provided100if [ "$API_URL" = "http://localhost:7860" ] && [ "$ENVIRONMENT" != "local" ]; then101    case $ENVIRONMENT in102        "staging")103            API_URL="https://algoryn-dots-ocr-idcard-staging.hf.space"104            ;;105        "production")106            API_URL="https://algoryn-dots-ocr-idcard.hf.space"107            ;;108        *)109            print_error "Unknown environment: $ENVIRONMENT. Use: local, staging, production"110            exit 1111            ;;112    esac113fi114 115# Check if Python is available116if ! command -v python3 &> /dev/null; then117    print_error "Python 3 is required but not installed"118    exit 1119fi120 121# Check if test images exist122if [ ! -f "tom_id_card_front.jpg" ] || [ ! -f "tom_id_card_back.jpg" ]; then123    print_error "Test images not found. Please ensure tom_id_card_front.jpg and tom_id_card_back.jpg are in the scripts directory"124    exit 1125fi126 127print_status "Starting Dots.OCR API Tests"128print_status "Environment: $ENVIRONMENT"129print_status "API URL: $API_URL"130print_status "Timeout: $TIMEOUT seconds"131 132# Run quick test if requested133if [ "$QUICK" = true ]; then134    print_status "Running quick test..."135    if python3 quick_test.py "$API_URL"; then136        print_success "Quick test passed"137        exit 0138    else139        print_error "Quick test failed"140        exit 1141    fi142fi143 144# Build test command145TEST_CMD="python3 test_api_endpoint.py --url $API_URL --timeout $TIMEOUT"146 147if [ "$VERBOSE" = true ]; then148    TEST_CMD="$TEST_CMD --verbose"149fi150 151if [ -n "$ROI" ]; then152    TEST_CMD="$TEST_CMD --roi '$ROI'"153fi154 155# Run comprehensive test156print_status "Running comprehensive API test..."157if eval $TEST_CMD; then158    print_success "All tests passed successfully!"159    exit 0160else161    print_error "Tests failed"162    exit 1163fi164