Spaces:
Paused
Paused
feat(api): fast FastAPI app + model loader refactor; add mock mode for tests\n\n- Add pyproject + setuptools config and console entrypoint\n- Implement enhanced field extraction + MRZ heuristics\n- Add response builder with compatibility for legacy MRZ fields\n- New preprocessing pipeline for PDFs/images\n- HF Spaces GPU: cache ENV, optional flash-attn, configurable base image\n- Add Make targets for Spaces GPU and local CPU\n- Add httpx for TestClient; tests pass in mock mode\n- Remove embedded model files and legacy app/modules
211e423
| # 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 | |