Spaces:
Paused
Paused
set -e # Exit the script if any statement returns a non-true return value | |
echo "=== Starting AI Toolkit ===" | |
echo "Working directory: $(pwd)" | |
echo "User: $(whoami)" | |
# Check if app has already been copied to /data | |
if [ ! -d "/data/ai-toolkit/ui" ]; then | |
echo "First run detected. Setting up persistent application..." | |
echo "This may take a moment..." | |
# Create base directory | |
mkdir -p /data/ai-toolkit | |
# Copy entire app to /data for full write access | |
echo "Copying application files..." | |
cp -r /app/ai-toolkit/* /data/ai-toolkit/ | |
echo "✓ Application copied to /data/ai-toolkit" | |
# Remove the build-time Prisma client | |
rm -rf /data/ai-toolkit/ui/node_modules/.prisma | |
echo "✓ Removed build-time Prisma client" | |
else | |
echo "✓ Application already exists in /data/ai-toolkit" | |
# Sync Python files in case they were updated (but preserve node_modules and database) | |
echo "Syncing Python toolkit updates..." | |
rsync -av --exclude='ui/node_modules' --exclude='ui/.next' --exclude='database' \ | |
/app/ai-toolkit/ /data/ai-toolkit/ | |
echo "✓ Python toolkit synced" | |
fi | |
# Ensure persistent directories exist | |
echo "Creating persistent directories..." | |
mkdir -p /data/ai-toolkit/database | |
echo "✓ Database directory ready" | |
# Set database URL to use organized persistent directory | |
export DATABASE_URL="file:/data/ai-toolkit/database/aitk_db.db" | |
echo "Database URL set to: $DATABASE_URL" | |
# Set HuggingFace cache directories to writable location | |
export HF_HOME="/data/huggingface" | |
export HUGGINGFACE_HUB_CACHE="/data/huggingface/hub" | |
export TRANSFORMERS_CACHE="/data/huggingface/transformers" | |
export DIFFUSERS_CACHE="/data/huggingface/diffusers" | |
echo "HuggingFace cache set to: $HF_HOME" | |
# Create HuggingFace cache directories | |
mkdir -p "$HF_HOME" | |
mkdir -p "$HUGGINGFACE_HUB_CACHE" | |
mkdir -p "$TRANSFORMERS_CACHE" | |
mkdir -p "$DIFFUSERS_CACHE" | |
# Change to the writable UI directory | |
echo "Changing to writable UI directory..." | |
cd /data/ai-toolkit/ui | |
echo "Current directory: $(pwd)" | |
# Run database migrations/setup if needed | |
echo "=== Setting up database ===" | |
# Generate Prisma client (now with full write access) | |
echo "Generating Prisma client..." | |
npx prisma generate --schema prisma/schema.prisma | |
echo "✓ Prisma client generated" | |
# Push schema to create database tables | |
echo "Creating database tables..." | |
npx prisma db push --schema prisma/schema.prisma --skip-generate | |
echo "✓ Database tables created" | |
# Start the application with HuggingFace cache environment variables | |
echo "" | |
echo "=== Starting application ===" | |
echo "Environment variables for HuggingFace:" | |
echo " HF_HOME=$HF_HOME" | |
echo " HUGGINGFACE_HUB_CACHE=$HUGGINGFACE_HUB_CACHE" | |
echo " TRANSFORMERS_CACHE=$TRANSFORMERS_CACHE" | |
echo " DIFFUSERS_CACHE=$DIFFUSERS_CACHE" | |
# Export variables again to ensure they're available to the Node process | |
export HF_HOME="/data/huggingface" | |
export HUGGINGFACE_HUB_CACHE="/data/huggingface/hub" | |
export TRANSFORMERS_CACHE="/data/huggingface/transformers" | |
export DIFFUSERS_CACHE="/data/huggingface/diffusers" | |
npm run start |