Spaces:
Sleeping
Sleeping
File size: 3,492 Bytes
24cd5a5 | 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 | #!/bin/bash
# Docker startup script with FAISS validation
# This runs before the main application starts in Docker
set -e # Exit on error
echo "=========================================="
echo " MAdVerse Startup - Validating Setup"
echo "=========================================="
echo ""
# Function to check if file is a Git LFS pointer
is_lfs_pointer() {
local file="$1"
if [ ! -f "$file" ]; then
return 1 # File doesn't exist
fi
# Check file size (LFS pointers are < 200 bytes)
local size=$(stat -f%z "$file" 2>/dev/null || stat -c%s "$file" 2>/dev/null || echo "0")
if [ "$size" -lt 200 ]; then
# Check if it starts with LFS header
if head -n 1 "$file" 2>/dev/null | grep -q "version https://git-lfs.github.com"; then
return 0 # Is an LFS pointer
fi
fi
return 1 # Not an LFS pointer
}
# Check critical files
echo "[CHECK] Validating FAISS index files..."
FAISS_INDEX="embeddings/faiss_indexes/madverse_index.faiss"
FAISS_METADATA="embeddings/faiss_indexes/id_to_metadata.pkl"
if [ ! -f "$FAISS_INDEX" ]; then
echo "β ERROR: FAISS index not found at $FAISS_INDEX"
echo ""
echo "SOLUTION: Run 'git lfs pull' before building Docker image"
exit 1
fi
if is_lfs_pointer "$FAISS_INDEX"; then
echo "β ERROR: FAISS index is a Git LFS pointer, not the actual file!"
echo ""
echo "This means Git LFS files were not downloaded."
echo ""
echo "SOLUTION:"
echo " 1. Install Git LFS: https://git-lfs.github.com/"
echo " 2. Run: git lfs install"
echo " 3. Run: git lfs pull"
echo " 4. Rebuild Docker: docker-compose up -d --build"
echo ""
exit 1
fi
# Check file size
FAISS_SIZE=$(stat -f%z "$FAISS_INDEX" 2>/dev/null || stat -c%s "$FAISS_INDEX" 2>/dev/null || echo "0")
MIN_SIZE=$((100 * 1024 * 1024)) # 100 MB minimum
if [ "$FAISS_SIZE" -lt "$MIN_SIZE" ]; then
echo "β ERROR: FAISS index file is too small ($FAISS_SIZE bytes)"
echo " Expected at least 100 MB. File may be corrupted."
echo ""
echo "SOLUTION: Re-pull from Git LFS:"
echo " git lfs pull"
echo " docker-compose up -d --build"
exit 1
fi
echo "β FAISS index OK ($(($FAISS_SIZE / 1024 / 1024)) MB)"
# Check metadata
if [ ! -f "$FAISS_METADATA" ]; then
echo "β ERROR: Metadata file not found at $FAISS_METADATA"
exit 1
fi
if is_lfs_pointer "$FAISS_METADATA"; then
echo "β ERROR: Metadata is a Git LFS pointer!"
echo " Run 'git lfs pull' before building Docker image"
exit 1
fi
echo "β Metadata file OK"
# Create runtime directories
echo ""
echo "[SETUP] Creating runtime directories..."
mkdir -p outputs uploads products_db
echo "β Directories created"
# Check environment variables
echo ""
echo "[CONFIG] Checking environment variables..."
if [ -z "$HF_TOKEN" ]; then
echo "β WARNING: HF_TOKEN not set"
echo " Image generation will use fallback (lower quality)"
else
echo "β HF_TOKEN configured"
fi
if [ -z "$GOOGLE_API_KEY" ] && [ -z "$GROQ_API_KEY" ] && [ -z "$ANTHROPIC_API_KEY" ]; then
echo "β WARNING: No text generation API keys found"
echo " Will use free Pollinations.ai (works but slower)"
else
echo "β Text generation API key(s) configured"
fi
echo ""
echo "=========================================="
echo " β Validation complete! Starting app..."
echo "=========================================="
echo ""
# Start the application
exec "$@"
|