Spaces:
Runtime error
Runtime error
| set -e | |
| echo "========================================" | |
| echo " VDS V2 Backend Starting..." | |
| echo "========================================" | |
| # ββ Step 0: Handle Google Cloud Credentials ββββββββββββββββββββββββββββββββββ | |
| if [ -n "$GCP_SERVICE_ACCOUNT" ]; then | |
| echo "βΆ Configuring Google Cloud credentials..." | |
| printf "%s" "$GCP_SERVICE_ACCOUNT" > /tmp/gcp_key.json | |
| # Check if file was written correctly and is not empty | |
| if [ -s /tmp/gcp_key.json ]; then | |
| export GOOGLE_APPLICATION_CREDENTIALS=/tmp/gcp_key.json | |
| echo "β Credentials configured (File size: $(stat -c%s /tmp/gcp_key.json) bytes)" | |
| else | |
| echo "β Error: Failed to write credentials file correctly." | |
| fi | |
| else | |
| echo "β οΈ GCP_SERVICE_ACCOUNT secret not found. Virtual Try-On may fail." | |
| fi | |
| # ββ Step 1: Start Ollama in background βββββββββββββββββββββββββββββββββββββββ | |
| echo "βΆ Starting Ollama service..." | |
| ollama serve & | |
| OLLAMA_PID=$! | |
| # ββ Step 2: Wait for Ollama to be ready ββββββββββββββββββββββββββββββββββββββ | |
| echo "β³ Waiting for Ollama to be ready..." | |
| MAX_RETRIES=30 | |
| COUNT=0 | |
| until curl -s http://127.0.0.1:11434 > /dev/null 2>&1; do | |
| COUNT=$((COUNT + 1)) | |
| if [ $COUNT -ge $MAX_RETRIES ]; then | |
| echo "β Ollama failed to start after ${MAX_RETRIES} retries." | |
| echo " Recommendation feature will be unavailable." | |
| echo " All other features will still work." | |
| break | |
| fi | |
| echo " Still waiting... (${COUNT}/${MAX_RETRIES})" | |
| sleep 2 | |
| done | |
| if curl -s http://127.0.0.1:11434 > /dev/null 2>&1; then | |
| echo "β Ollama is running" | |
| # ββ Step 3: Pull base LLM model ββββββββββββββββββββββββββββββββββββββββββ | |
| echo "βΆ Pulling qwen2.5:3b base model (this may take a few minutes)..." | |
| ollama pull qwen2.5:3b | |
| echo "β Base model ready" | |
| # ββ Step 4: Build the custom smartfit model from Modelfile βββββββββββββββ | |
| if [ -f "/app/recommendation/Modelfile.txt" ]; then | |
| echo "βΆ Building smartfit custom model..." | |
| ollama create smartfit -f /app/recommendation/Modelfile.txt | |
| echo "β smartfit model ready" | |
| else | |
| echo "β οΈ recommendation/Modelfile.txt not found β smartfit model not created." | |
| echo " Recommendation feature may use base model instead." | |
| fi | |
| else | |
| echo "β οΈ Ollama did not start. Continuing without recommendation feature." | |
| fi | |
| # ββ Step 5: Start FastAPI backend ββββββββββββββββββββββββββββββββββββββββββββ | |
| echo "" | |
| echo "========================================" | |
| echo " Starting FastAPI on port 7860..." | |
| echo "========================================" | |
| exec uvicorn main:app --host 0.0.0.0 --port 7860 | |