jacky3102 commited on
Commit
325579d
·
verified ·
1 Parent(s): fdaf189

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +38 -32
Dockerfile CHANGED
@@ -1,39 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  FROM python:3.11-slim
2
 
3
- # 安装系统依赖(含 sox、libsndfile)
4
- RUN apt-get update && apt-get install -y \
5
- sox \
6
- libsox-fmt-all \
7
- libsndfile1 \
8
- ffmpeg \
9
- git \
10
  && rm -rf /var/lib/apt/lists/*
11
 
12
- WORKDIR /app
13
-
14
- # 先装 CPU 版 torch(HF 免费 Space 无 GPU)
15
- RUN pip install --no-cache-dir \
16
- torch==2.3.1+cpu \
17
- torchaudio==2.3.1+cpu \
18
- --index-url https://download.pytorch.org/whl/cpu
19
-
20
- # 再装其他依赖
21
- RUN pip install --no-cache-dir \
22
- transformers==4.57.3 \
23
- accelerate \
24
- einops \
25
- gradio \
26
- fastapi \
27
- uvicorn[standard] \
28
- python-multipart \
29
- librosa \
30
- soundfile \
31
- numpy \
32
- onnxruntime \
33
- qwen-tts
34
-
35
- COPY app.py .
36
 
37
  EXPOSE 7860
38
 
39
- CMD ["python", "app.py"]
 
 
 
 
 
 
 
 
 
1
+ # ---- Build stage: 编译 llama.cpp 的 llama-server (CPU only) ----
2
+ FROM python:3.11-slim AS build
3
+
4
+ RUN apt-get update && apt-get install -y --no-install-recommends \
5
+ build-essential cmake git libcurl4-openssl-dev ca-certificates \
6
+ && rm -rf /var/lib/apt/lists/*
7
+
8
+ RUN git clone --depth 1 https://github.com/ggml-org/llama.cpp /llama.cpp
9
+ WORKDIR /llama.cpp
10
+
11
+ # GGML_NATIVE=OFF: HF Space的CPU型号不确定,不能假设AVX512等指令集,
12
+ # 用通用编译避免"illegal instruction"崩溃。LLAMA_CURL=ON 让 -hf 直接从HF拉模型。
13
+ RUN cmake -B build -DGGML_NATIVE=OFF -DLLAMA_CURL=ON -DCMAKE_BUILD_TYPE=Release \
14
+ && cmake --build build --target llama-server -j "$(nproc)"
15
+
16
+ # ---- Runtime stage ----
17
  FROM python:3.11-slim
18
 
19
+ RUN apt-get update && apt-get install -y --no-install-recommends \
20
+ libcurl4 ca-certificates \
 
 
 
 
 
21
  && rm -rf /var/lib/apt/lists/*
22
 
23
+ COPY --from=build /llama.cpp/build/bin/llama-server /usr/local/bin/llama-server
24
+
25
+ # HF Space Docker容器默认以非root用户运行,/tmp通常可写,用它做模型缓存目录
26
+ ENV HF_HOME=/tmp/hf_cache
27
+ RUN mkdir -p /tmp/hf_cache && chmod -R 777 /tmp/hf_cache
28
+
29
+ # ---- 可在Space的 Settings > Variables 里覆盖,无需重新构建镜像 ----
30
+ ENV MODEL_REPO="Qwen/Qwen3-4B-Instruct-2507-GGUF"
31
+ ENV MODEL_QUANT="Q4_K_M"
32
+ ENV CTX_SIZE="4096"
33
+ ENV N_THREADS="2"
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
  EXPOSE 7860
36
 
37
+ # --jinja: 启用chat template里的tool-calling语法解析,让 /v1/chat/completions
38
+ # 支持传 tools=[...] 并正确输出 tool_calls
39
+ CMD ["sh", "-c", "llama-server \
40
+ -hf ${MODEL_REPO}:${MODEL_QUANT} \
41
+ --host 0.0.0.0 \
42
+ --port 7860 \
43
+ -c ${CTX_SIZE} \
44
+ -t ${N_THREADS} \
45
+ --jinja"]