File size: 2,241 Bytes
3a32bd4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/bin/sh
set -e

echo "============================================"
echo "  Certificate Verification AI Service"
echo "============================================"
echo "Starting at $(date)"
echo "Port: ${PORT:-8080}"
echo "Workers: ${WORKERS:-1}"
echo "Log level: ${LOG_LEVEL:-info}"
echo "Skip models: ${SKIP_MODEL_LOADING:-false}"
echo "============================================"

# Validate required environment variables
missing_vars=""
if [ -z "$SUPABASE_URL" ]; then
    missing_vars="$missing_vars SUPABASE_URL"
fi
if [ -z "$SUPABASE_KEY" ]; then
    missing_vars="$missing_vars SUPABASE_KEY"
fi
if [ -z "$OCRSPACE_API_KEY" ]; then
    missing_vars="$missing_vars OCRSPACE_API_KEY"
fi

if [ -n "$missing_vars" ]; then
    echo "WARNING: Missing environment variables:$missing_vars"
    echo "The service may not function correctly without these."
    echo "See .env.example for required configuration."
fi

# Pre-download models if not present and not skipped
if [ "${SKIP_MODEL_LOADING}" != "true" ]; then
    echo "Checking AI model files..."

    # Check YOLO model
    if [ ! -f "models/best.pt" ] && [ ! -f "yolo_seal_model/best.pt" ]; then
        echo "YOLO model not found locally. It will be downloaded on first request."
    else
        echo "YOLO model: OK"
    fi

    # Check ViT model
    if [ ! -f "vit_seal_checker.pth" ]; then
        echo "ViT model not found locally. It will be downloaded on first request."
    else
        echo "ViT model: OK"
    fi
else
    echo "Model loading SKIPPED (SKIP_MODEL_LOADING=true)"
    echo "Running in lightweight mode (OCR + database verification only)"
fi

echo "============================================"
echo "Launching Gunicorn with Uvicorn workers..."
echo "============================================"

# Start Gunicorn with Uvicorn worker class
exec gunicorn api:app \
    --bind "0.0.0.0:${PORT:-8080}" \
    --worker-class uvicorn.workers.UvicornWorker \
    --workers "${WORKERS:-1}" \
    --timeout "${GUNICORN_TIMEOUT:-300}" \
    --keep-alive "${GUNICORN_KEEP_ALIVE:-5}" \
    --graceful-timeout "${GUNICORN_GRACEFUL_TIMEOUT:-120}" \
    --log-level "${LOG_LEVEL:-info}" \
    --access-logfile - \
    --error-logfile - \
    --config gunicorn.conf.py