chore(deploy): one-click launchers and HF Spaces Dockerfile
Browse files- .dockerignore +11 -0
- Dockerfile +23 -0
- scripts/start.bat +2 -0
- scripts/start.ps1 +54 -0
- scripts/start.sh +53 -0
.dockerignore
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.venv
|
| 2 |
+
__pycache__
|
| 3 |
+
*.pyc
|
| 4 |
+
node_modules
|
| 5 |
+
web/dist
|
| 6 |
+
server/static
|
| 7 |
+
.pytest_cache
|
| 8 |
+
.git
|
| 9 |
+
docs
|
| 10 |
+
*.md
|
| 11 |
+
!README.md
|
Dockerfile
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# syntax=docker/dockerfile:1.6
|
| 2 |
+
|
| 3 |
+
FROM node:20-alpine AS web
|
| 4 |
+
WORKDIR /web
|
| 5 |
+
COPY web/package*.json ./
|
| 6 |
+
RUN npm ci --no-audit --no-fund
|
| 7 |
+
COPY web/ ./
|
| 8 |
+
RUN npm run build
|
| 9 |
+
|
| 10 |
+
FROM python:3.11-slim
|
| 11 |
+
ENV HF_HOME=/tmp/hf \
|
| 12 |
+
PYTHONUNBUFFERED=1 \
|
| 13 |
+
PORT=7860
|
| 14 |
+
WORKDIR /app
|
| 15 |
+
RUN apt-get update \
|
| 16 |
+
&& apt-get install -y --no-install-recommends libsndfile1 ffmpeg \
|
| 17 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 18 |
+
COPY requirements.txt ./
|
| 19 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 20 |
+
COPY server/ server/
|
| 21 |
+
COPY --from=web /web/dist server/static/
|
| 22 |
+
EXPOSE 7860
|
| 23 |
+
CMD ["uvicorn", "server.main:app", "--host", "0.0.0.0", "--port", "7860"]
|
scripts/start.bat
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@echo off
|
| 2 |
+
powershell -ExecutionPolicy Bypass -File "%~dp0start.ps1" %*
|
scripts/start.ps1
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
param(
|
| 2 |
+
[string]$BindHost = "127.0.0.1",
|
| 3 |
+
[int]$Port = 7860
|
| 4 |
+
)
|
| 5 |
+
|
| 6 |
+
$ErrorActionPreference = "Stop"
|
| 7 |
+
$Root = Resolve-Path "$PSScriptRoot/.."
|
| 8 |
+
Set-Location $Root
|
| 9 |
+
|
| 10 |
+
$python = Get-Command py -ErrorAction SilentlyContinue
|
| 11 |
+
if (-not $python) {
|
| 12 |
+
Write-Error "Python launcher 'py' not found. Install Python 3.11+ from python.org."
|
| 13 |
+
exit 1
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
if (-not (Test-Path ".venv")) {
|
| 17 |
+
Write-Host "==> Creating venv (.venv)"
|
| 18 |
+
& py -3.11 -m venv .venv
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
$activate = ".venv/Scripts/Activate.ps1"
|
| 22 |
+
. $activate
|
| 23 |
+
|
| 24 |
+
$reqHash = (Get-FileHash requirements.txt -Algorithm SHA1).Hash
|
| 25 |
+
$marker = ".venv/.installed-marker"
|
| 26 |
+
if (-not (Test-Path $marker) -or (Get-Content $marker) -ne $reqHash) {
|
| 27 |
+
Write-Host "==> Installing python deps"
|
| 28 |
+
pip install --upgrade pip
|
| 29 |
+
pip install -r requirements.txt
|
| 30 |
+
Set-Content $marker $reqHash
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
if (-not (Test-Path "web/node_modules")) {
|
| 34 |
+
Write-Host "==> Installing web deps"
|
| 35 |
+
Push-Location web
|
| 36 |
+
npm ci
|
| 37 |
+
Pop-Location
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
if (-not (Test-Path "server/static/index.html")) {
|
| 41 |
+
Write-Host "==> Building web"
|
| 42 |
+
Push-Location web
|
| 43 |
+
npm run build
|
| 44 |
+
Pop-Location
|
| 45 |
+
if (Test-Path "server/static") { Remove-Item -Recurse -Force "server/static" }
|
| 46 |
+
New-Item -ItemType Directory -Force "server/static" | Out-Null
|
| 47 |
+
Copy-Item -Recurse "web/dist/*" "server/static/"
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
$env:PYTORCH_ENABLE_MPS_FALLBACK = "1"
|
| 51 |
+
$Url = "http://${BindHost}:$Port"
|
| 52 |
+
Write-Host "==> Serving on $Url"
|
| 53 |
+
Start-Process $Url
|
| 54 |
+
uvicorn server.main:app --host $BindHost --port $Port
|
scripts/start.sh
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
# One-click: venv -> install -> build SPA -> serve -> open browser.
|
| 3 |
+
set -euo pipefail
|
| 4 |
+
|
| 5 |
+
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
| 6 |
+
cd "$ROOT"
|
| 7 |
+
|
| 8 |
+
if command -v python3.11 >/dev/null 2>&1; then
|
| 9 |
+
PY=python3.11
|
| 10 |
+
elif command -v python3 >/dev/null 2>&1; then
|
| 11 |
+
PY=python3
|
| 12 |
+
else
|
| 13 |
+
echo "ERROR: python3.11 (or python3) not found. Install Python 3.11+." >&2
|
| 14 |
+
exit 1
|
| 15 |
+
fi
|
| 16 |
+
|
| 17 |
+
if [ ! -d .venv ]; then
|
| 18 |
+
echo "==> Creating venv (.venv) with $PY"
|
| 19 |
+
"$PY" -m venv .venv
|
| 20 |
+
fi
|
| 21 |
+
# shellcheck source=/dev/null
|
| 22 |
+
. .venv/bin/activate
|
| 23 |
+
|
| 24 |
+
REQ_HASH=$(shasum requirements.txt | awk '{print $1}')
|
| 25 |
+
MARKER=".venv/.installed-marker"
|
| 26 |
+
if [ ! -f "$MARKER" ] || [ "$(cat "$MARKER")" != "$REQ_HASH" ]; then
|
| 27 |
+
echo "==> Installing python deps"
|
| 28 |
+
pip install --upgrade pip
|
| 29 |
+
pip install -r requirements.txt
|
| 30 |
+
echo "$REQ_HASH" > "$MARKER"
|
| 31 |
+
fi
|
| 32 |
+
|
| 33 |
+
if [ ! -d web/node_modules ]; then
|
| 34 |
+
echo "==> Installing web deps"
|
| 35 |
+
(cd web && npm ci)
|
| 36 |
+
fi
|
| 37 |
+
|
| 38 |
+
if [ ! -d server/static ] || [ ! -f web/dist/index.html ]; then
|
| 39 |
+
echo "==> Building web"
|
| 40 |
+
(cd web && npm run build)
|
| 41 |
+
rm -rf server/static
|
| 42 |
+
mkdir -p server/static
|
| 43 |
+
cp -R web/dist/* server/static/
|
| 44 |
+
fi
|
| 45 |
+
|
| 46 |
+
export PYTORCH_ENABLE_MPS_FALLBACK="${PYTORCH_ENABLE_MPS_FALLBACK:-1}"
|
| 47 |
+
HOST="${HOST:-127.0.0.1}"
|
| 48 |
+
PORT="${PORT:-7860}"
|
| 49 |
+
URL="http://$HOST:$PORT"
|
| 50 |
+
|
| 51 |
+
echo "==> Serving on $URL"
|
| 52 |
+
( sleep 2 && python -m webbrowser "$URL" ) &
|
| 53 |
+
exec uvicorn server.main:app --host "$HOST" --port "$PORT"
|