22333Misaka commited on
Commit
71907f3
·
verified ·
1 Parent(s): af8a4da

Upload 4 files

Browse files
Files changed (4) hide show
  1. Dockerfile +67 -0
  2. download_support_models.py +18 -0
  3. monitor_and_upload.sh +52 -0
  4. start.sh +12 -0
Dockerfile ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 使用官方 PyTorch 基础镜像
2
+ FROM pytorch/pytorch:2.3.1-cuda11.8-cudnn8-runtime
3
+
4
+ # 切换到 root 用户以进行系统级安装
5
+ USER root
6
+
7
+ # 设置环境变量
8
+ ENV PYTHONUNBUFFERED=1 \
9
+ PIP_DISABLE_PIP_VERSION_CHECK=1 \
10
+ PIP_PREFER_BINARY=1 \
11
+ NUMBA_CACHE_DIR=/tmp/numba_cache
12
+
13
+ # 设置工作目录
14
+ WORKDIR /app
15
+
16
+ # 安装系统依赖 (--- 在这里添加了 curl ---)
17
+ RUN apt-get update && \
18
+ apt-get install -y --no-install-recommends \
19
+ wget curl ffmpeg libsox-dev git \
20
+ build-essential cmake ninja-build pkg-config && \
21
+ rm -rf /var/lib/apt/lists/* && \
22
+ mkdir -p /tmp/numba_cache && chmod -R 777 /tmp/numba_cache
23
+
24
+ # 创建并授权 NLTK 数据目录
25
+ RUN mkdir -p /nltk_data && chmod 777 /nltk_data
26
+
27
+ # 克隆 GPT-SoVITS 仓库
28
+ RUN git clone --depth 1 https://github.com/RVC-Boss/GPT-SoVITS.git /app
29
+
30
+ # 安装 Python 依赖
31
+ RUN pip install --upgrade pip && \
32
+ pip install --no-cache-dir -r /app/requirements.txt && \
33
+ pip install --no-cache-dir --force-reinstall numpy==1.23.5 librosa==0.9.2 numba==0.56.4 && \
34
+ pip install --no-cache-dir fastapi uvicorn soundfile huggingface_hub ffmpeg-python
35
+
36
+ # 预下载 NLTK 数据包
37
+ 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')"
38
+
39
+ # 预下载官方支持模型
40
+ COPY download_support_models.py /app/download_support_models.py
41
+ RUN python /app/download_support_models.py || true
42
+
43
+ # --- 从 Hugging Face Spaces 下载您自己的模型权重 ---
44
+ ARG GPT_URL="https://huggingface.co/spaces/snsbhg/1111/resolve/main/weights/shantianliang_proplus_e32.ckpt"
45
+ ARG SOVITS_URL="https://huggingface.co/spaces/snsbhg/1111/resolve/main/weights/shantianliang_proplus_e8_s192.pth"
46
+ RUN mkdir -p /app/pretrained_models/shantianliang
47
+ RUN wget -nv "$GPT_URL" -O /app/pretrained_models/shantianliang/shantianliang_proplus_e32.ckpt && \
48
+ wget -nv "$SOVITS_URL" -O /app/pretrained_models/shantianliang/shantianliang_proplus_e8_s192.pth
49
+
50
+ # 复制参考音频
51
+ COPY reference_audio/ /app/reference_audio/
52
+
53
+ # --- [新] 复制监控和启动脚本 ---
54
+ COPY monitor_and_upload.sh /app/monitor_and_upload.sh
55
+ COPY start.sh /app/start.sh
56
+
57
+ # --- [新] 赋予脚本执行权限 ---
58
+ RUN chmod +x /app/start.sh /app/monitor_and_upload.sh
59
+
60
+ # 更改 /app 目录所有权
61
+ RUN chown -R 1000:1000 /app
62
+
63
+ # 暴露 API 端口
64
+ EXPOSE 7860
65
+
66
+ # --- [修改] 使用 start.sh 脚本作为启动命令 ---
67
+ CMD ["/app/start.sh"]
download_support_models.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from huggingface_hub import snapshot_download
2
+ import os
3
+
4
+ # [关键修改] 将目标文件夹指向程序期望的正确路径
5
+ target = "GPT_SoVITS/pretrained_models"
6
+ os.makedirs(target, exist_ok=True)
7
+
8
+ try:
9
+ snapshot_download(
10
+ repo_id="lj1995/GPT-SoVITS",
11
+ repo_type="model",
12
+ local_dir=target,
13
+ # 注意:这里我们下载全部预ciallo模型,而不仅仅是sv和chinese
14
+ # allow_patterns=["sv/*", "chinese*"], # 暂时注释掉,确保所有基础模型都被下载ciallo
15
+ )
16
+ print("Support models downloaded to ./GPT_SoVITS/pretrained_models")
17
+ except Exception as e:
18
+ print("Skipping support model download:", e)
monitor_and_upload.sh ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # --- 配置区 ---
4
+ # Alist 服务器地址 (保持不变)
5
+ ALIST_URL="https://o.114514heihei.eu.org/od"
6
+ # 本地日志文件路径
7
+ LOG_FILE="/app/size_monitor.log"
8
+ # 上传到 Alist 的路径和文件名
9
+ REMOTE_PATH="/size_monitor.log"
10
+ # 监控和上传的间隔时间(秒)
11
+ SLEEP_INTERVAL=300 # 5分钟
12
+
13
+ # --- 脚本主逻辑 ---
14
+
15
+ echo "--- Starting Filesystem Monitor and Uploader ---" > $LOG_FILE
16
+ echo "--- To enable uploads, set the ALIST_TOKEN environment variable. ---" >> $LOG_FILE
17
+
18
+ while true; do
19
+ # --- 1. 记录大小 ---
20
+ TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
21
+ echo "--- Log entry at $TIMESTAMP ---" >> $LOG_FILE
22
+
23
+ # 监控 /app 目录下所有子目录的大小
24
+ du -sh /app/* >> $LOG_FILE
25
+ echo "" >> $LOG_FILE
26
+
27
+ # --- 2. 上传日志 (检查环境变量是否存在) ---
28
+ if [ -n "$ALIST_TOKEN" ]; then
29
+ echo "Uploading log file to Alist server at $TIMESTAMP..."
30
+
31
+ # 使用 curl 调用 Alist API 上传文件
32
+ # -s: 静默模式
33
+ # -o /dev/null: 丢弃标准输出
34
+ # -w "%{http_code}": 只输出 HTTP 状态码
35
+ HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" -X PUT \
36
+ --url "$ALIST_URL/api/fs/put" \
37
+ -H "Authorization: $ALIST_TOKEN" \
38
+ -H "File-Path: $REMOTE_PATH" \
39
+ -T "$LOG_FILE")
40
+
41
+ if [ "$HTTP_STATUS" -eq 200 ]; then
42
+ echo "Log file uploaded successfully (HTTP Status: $HTTP_STATUS)."
43
+ else
44
+ echo "Error: Failed to upload log file (HTTP Status: $HTTP_STATUS)."
45
+ fi
46
+ else
47
+ echo "Warning: ALIST_TOKEN environment variable is not set. Skipping upload."
48
+ fi
49
+
50
+ # --- 3. 等待 ---
51
+ sleep $SLEEP_INTERVAL
52
+ done
start.sh ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # 赋予监控脚本执行权限
4
+ chmod +x /app/monitor_and_upload.sh
5
+
6
+ # 在后台启动监控和上传脚本
7
+ echo "Starting background monitor and uploader..."
8
+ /app/monitor_and_upload.sh &
9
+
10
+ # 在前台启动主应用程序
11
+ echo "Starting main application (api_v2.py)..."
12
+ exec python api_v2.py -a "0.0.0.0" -p "7860" -c "GPT_SoVITS/configs/tts_infer.yaml"