Spaces:
Running
Running
| set -e | |
| echo "=============================================" | |
| echo " Fragmenta — Docker Edition" | |
| echo "=============================================" | |
| # Use environment variables with sensible defaults | |
| HOST="${FLASK_HOST:-0.0.0.0}" | |
| PORT="${FLASK_PORT:-5001}" | |
| echo "Host: ${HOST}" | |
| echo "Port: ${PORT}" | |
| echo "=============================================" | |
| cd /app | |
| # ---- Ensure runtime directories exist (may be empty volume mounts) ---- | |
| mkdir -p /app/models/pretrained /app/models/fine_tuned /app/models/config \ | |
| /app/data /app/output /app/logs /app/config 2>/dev/null || true | |
| # ---- Diagnostics (helps debug failures on new machines) ---- | |
| echo "[startup] Python: $(python --version 2>&1)" | |
| echo "[startup] Working dir: $(pwd)" | |
| echo "[startup] User: $(whoami) (uid=$(id -u))" | |
| # Smoke-test: verify core imports and detect GPU | |
| echo "[startup] Checking core Python imports and GPU…" | |
| python -c " | |
| import flask, flask_cors, torch, torchaudio, soundfile | |
| print(f' Flask {flask.__version__} | torch {torch.__version__}') | |
| print(f' CUDA build: {torch.version.cuda or \"none\"}') | |
| if torch.cuda.is_available(): | |
| name = torch.cuda.get_device_name(0) | |
| vram = torch.cuda.get_device_properties(0).total_memory / 1024**3 | |
| print(f' GPU: {name} ({vram:.1f} GB VRAM) — CUDA ready') | |
| else: | |
| print(' No CUDA GPU detected — will run on CPU') | |
| print(' If you have an NVIDIA GPU, check:') | |
| print(' 1. Run \"docker compose up\" (not \"docker-compose up\")') | |
| print(' 2. Docker Desktop is using the WSL2 backend') | |
| print(' 3. \"nvidia-smi\" works on the host') | |
| " || { | |
| echo "ERROR: Core Python imports failed. Check requirements." | |
| exit 1 | |
| } | |
| # Ensure model config files exist (they may be missing if /app/models is | |
| # an empty volume mount). Fallback copies are baked into the image under | |
| # /opt/fragmenta-defaults/models/config/ during the Docker build. | |
| if [ -d /opt/fragmenta-defaults/models/config ]; then | |
| for f in /opt/fragmenta-defaults/models/config/*; do | |
| fname=$(basename "$f") | |
| if [ ! -f "/app/models/config/${fname}" ]; then | |
| echo "[startup] Restoring default config: ${fname}" | |
| cp "$f" "/app/models/config/${fname}" 2>/dev/null || true | |
| fi | |
| done | |
| fi | |
| echo "[startup] Starting Fragmenta on ${HOST}:${PORT}" | |
| echo "Open http://localhost:${PORT} in your browser" | |
| echo "=============================================" | |
| # Run Flask directly via Python (same way the desktop app does it) | |
| exec python -c " | |
| import os, sys | |
| sys.path.insert(0, '/app') | |
| os.environ['FLASK_HOST'] = '${HOST}' | |
| os.environ['FLASK_PORT'] = '${PORT}' | |
| from app.backend.app import app, QuietWSGIRequestHandler | |
| print('[server] Flask app imported — starting…', flush=True) | |
| app.run( | |
| host='${HOST}', | |
| port=int('${PORT}'), | |
| debug=False, | |
| use_reloader=False, | |
| request_handler=QuietWSGIRequestHandler, | |
| threaded=True | |
| ) | |
| " | |