File size: 2,499 Bytes
63f0b06
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
509c3c0
63f0b06
 
 
509c3c0
 
 
63f0b06
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/bin/bash
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))"

# Quick smoke-test: can we import the core deps? (avoid CUDA init — it's slow)
echo "[startup] Checking core Python imports…"
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\"}')
print('  GPU detection deferred to first request (faster startup)')
" || {
    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
)
"