dev-scezui commited on
Commit
832adb1
Β·
verified Β·
1 Parent(s): d238eeb

Upload 2 files

Browse files
Files changed (2) hide show
  1. Dockerfile +63 -0
  2. entrypoint_hf.sh +30 -0
Dockerfile ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ============================================================
2
+ # Fish Speech API Server β€” HuggingFace Spaces Dockerfile
3
+ # Target: GPU Space (T4 or better) on HuggingFace
4
+ # Port: 7860 (required by HF Spaces)
5
+ # ============================================================
6
+
7
+ FROM nvidia/cuda:12.6.1-devel-ubuntu22.04
8
+
9
+ # HF Spaces runs containers as UID 1000
10
+ ARG USERNAME=user
11
+ ARG USER_UID=1000
12
+ ARG USER_GID=1000
13
+
14
+ ENV DEBIAN_FRONTEND=noninteractive \
15
+ PYTHONDONTWRITEBYTECODE=1 \
16
+ PYTHONUNBUFFERED=1 \
17
+ # Where the model will be downloaded at startup
18
+ MODEL_DIR=/app/models/fish-speech-1.5 \
19
+ # HF Spaces requires the app to bind to 7860
20
+ APP_PORT=7860 \
21
+ APP_BIND=0.0.0.0 \
22
+ APP_WORKERS=1
23
+
24
+ WORKDIR /app
25
+
26
+ # ── System dependencies ──────────────────────────────────────
27
+ RUN apt-get update -q && \
28
+ apt-get install -fyq \
29
+ bash git cmake curl \
30
+ portaudio19-dev \
31
+ python3 python3-pip \
32
+ time && \
33
+ apt-get clean && \
34
+ rm -rf /var/lib/apt/lists/*
35
+
36
+ # ── Python dependencies ──────────────────────────────────────
37
+ # Clone the repo so we get the submodule (fish_speech) too.
38
+ # We pin to main; swap for a specific commit/tag for reproducibility.
39
+ RUN git clone --recurse-submodules \
40
+ https://github.com/EvilFreelancer/docker-fish-speech-server.git \
41
+ /app
42
+
43
+ RUN pip install --no-cache-dir -r /app/requirements.txt && \
44
+ pip install --no-cache-dir "huggingface_hub[cli]"
45
+
46
+ # ── Non-root user (required by HF Spaces) ────────────────────
47
+ RUN groupadd --gid ${USER_GID} ${USERNAME} && \
48
+ useradd --uid ${USER_UID} --gid ${USER_GID} -m ${USERNAME} && \
49
+ mkdir -p /app/models && \
50
+ chown -R ${USER_UID}:${USER_GID} /app
51
+
52
+ USER ${USERNAME}
53
+
54
+ # ── Entrypoint: download model on first run, then start API ──
55
+ # HF Spaces GPU Spaces provide CUDA at runtime via the host driver.
56
+ # The model download is deferred to startup so the Docker image
57
+ # itself stays small and HF caching can be reused across restarts.
58
+ COPY --chown=${USER_UID}:${USER_GID} entrypoint_hf.sh /app/entrypoint_hf.sh
59
+ RUN chmod +x /app/entrypoint_hf.sh
60
+
61
+ EXPOSE 7860
62
+
63
+ ENTRYPOINT ["/app/entrypoint_hf.sh"]
entrypoint_hf.sh ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # entrypoint_hf.sh β€” runs inside the HF Spaces container at startup
3
+
4
+ set -e
5
+ cd "$(dirname "$0")"
6
+
7
+ MODEL_REPO="fishaudio/fish-speech-1.5"
8
+ MODEL_DIR="${MODEL_DIR:-/app/models/fish-speech-1.5}"
9
+
10
+ echo "==> Checking for model at ${MODEL_DIR} ..."
11
+ if [ ! -f "${MODEL_DIR}/model.pth" ] && [ ! -f "${MODEL_DIR}/config.json" ]; then
12
+ echo "==> Model not found. Downloading from HuggingFace Hub..."
13
+ huggingface-cli download "${MODEL_REPO}" \
14
+ --local-dir "${MODEL_DIR}" \
15
+ --local-dir-use-symlinks False
16
+ echo "==> Model download complete."
17
+ else
18
+ echo "==> Model already present, skipping download."
19
+ fi
20
+
21
+ APP_PORT="${APP_PORT:-7860}"
22
+ APP_BIND="${APP_BIND:-0.0.0.0}"
23
+ APP_WORKERS="${APP_WORKERS:-1}"
24
+
25
+ echo "==> Starting Fish Speech API on ${APP_BIND}:${APP_PORT} ..."
26
+ exec uvicorn \
27
+ --host "${APP_BIND}" \
28
+ --port "${APP_PORT}" \
29
+ --workers "${APP_WORKERS}" \
30
+ main:app