1 / Dockerfile
22333Misaka's picture
Update Dockerfile
116361e verified
# 使用官方 PyTorch 基础镜像
FROM pytorch/pytorch:2.3.1-cuda11.8-cudnn8-runtime
# 切换到 root 用户以进行系统级安装
USER root
# 设置环境变量
ENV PYTHONUNBUFFERED=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PIP_PREFER_BINARY=1 \
NUMBA_CACHE_DIR=/tmp/numba_cache
# 设置工作目录
WORKDIR /app
# 安装系统依赖 (已包含 curl 和 wget)
RUN apt-get update && \
apt-get install -y --no-install-recommends \
wget curl ffmpeg libsox-dev git \
build-essential cmake ninja-build pkg-config && \
rm -rf /var/lib/apt/lists/* && \
mkdir -p /tmp/numba_cache && chmod -R 777 /tmp/numba_cache
# 创建并授权 NLTK 数据目录
RUN mkdir -p /nltk_data && chmod 777 /nltk_data
# 克隆 GPT-SoVITS 仓库
RUN git clone --depth 1 https://github.com/RVC-Boss/GPT-SoVITS.git /app
# 安装 Python 依赖
RUN pip install --upgrade pip && \
pip install --no-cache-dir -r /app/requirements.txt && \
pip install --no-cache-dir --force-reinstall numpy==1.23.5 librosa==0.9.2 numba==0.56.4 && \
pip install --no-cache-dir fastapi uvicorn soundfile huggingface_hub ffmpeg-python
# 预下载 NLTK 数据包
RUN python -c "import nltk; nltk.download('punkt', quiet=True, download_dir='/nltk_data'); nltk.download('averaged_perceptron_tagger', quiet=True, download_dir='/nltk_data'); nltk.download('averaged_perceptron_tagger_eng', quiet=True, download_dir='/nltk_data')"
# 预下载官方支持模型
COPY download_support_models.py /app/download_support_models.py
RUN python /app/download_support_models.py || true
# --- 从 Hugging Face Spaces 下载您自己的模型权重 ---
ARG GPT_URL="https://huggingface.co/spaces/snsbhg/1111/resolve/main/weights/shantianliang_proplus_e32.ckpt"
ARG SOVITS_URL="https://huggingface.co/spaces/snsbhg/1111/resolve/main/weights/shantianliang_proplus_e8_s192.pth"
RUN mkdir -p /app/pretrained_models/shantianliang && \
wget -nv "$GPT_URL" -O /app/pretrained_models/shantianliang/shantianliang_proplus_e32.ckpt && \
wget -nv "$SOVITS_URL" -O /app/pretrained_models/shantianliang/shantianliang_proplus_e8_s192.pth
# --- [修改] 将本地复制改为从URL下载参考音频 ---
RUN echo "--- Downloading reference audio file ---" && \
mkdir -p /app/reference_audio && \
wget -nv "https://huggingface.co/spaces/Awsl1111ddd/cialloapi/raw/main/reference_audio/ref_shantianliang_1.wav" \
-O /app/reference_audio/ref_shantianliang_1.wav && \
echo "--- Reference audio downloaded successfully ---"
# 复制监控和启动脚本
COPY monitor_and_upload.sh /app/monitor_and_upload.sh
COPY start.sh /app/start.sh
# 赋予脚本执行权限
RUN chmod +x /app/start.sh /app/monitor_and_upload.sh
# 更改 /app 目录所有权
RUN chown -R 1000:1000 /app
# 暴露 API 端口
EXPOSE 7860
# 使用 start.sh 脚本作为启动命令
CMD ["/app/start.sh"]