simler commited on
Commit
fdab6dc
·
verified ·
1 Parent(s): b245537

Upload 2 files

Browse files
Files changed (2) hide show
  1. Dockerfile +10 -5
  2. app.py +14 -5
Dockerfile CHANGED
@@ -7,16 +7,21 @@ RUN apt-get update && apt-get install -y \
7
  git ffmpeg build-essential cmake libmecab-dev mecab-ipadic-utf8 \
8
  && rm -rf /var/lib/apt/lists/*
9
 
10
- # 安装所有必要库
11
  RUN pip install --no-cache-dir \
12
- git+https://github.com/High-Logic/Genie-TTS.git \
13
- python-multipart uvicorn fastapi
14
 
15
- # 镜像权限处理
16
  COPY . /app
 
 
 
 
 
17
  RUN chmod -R 777 /app
18
 
19
  EXPOSE 7860
20
 
21
  # 使用直接启动模式
22
- CMD ["python", "app.py"]
 
7
  git ffmpeg build-essential cmake libmecab-dev mecab-ipadic-utf8 \
8
  && rm -rf /var/lib/apt/lists/*
9
 
10
+ # 安装 genie_tts 的依赖(不安装 genie_tts 本身,使用本地源码)
11
  RUN pip install --no-cache-dir \
12
+ onnx onnxruntime==1.22.1 tokenizers numpy soundfile soxr pyyaml \
13
+ python-multipart uvicorn fastapi huggingface_hub
14
 
15
+ # 复制所有文件(包括本地 genie_tts 源码)
16
  COPY . /app
17
+
18
+ # 预下载 GenieData 资源(避免每次启动都下载)
19
+ RUN python -c "from huggingface_hub import snapshot_download; snapshot_download(repo_id='High-Logic/Genie', allow_patterns=['GenieData/*'], local_dir='/app', local_dir_use_symlinks=False)"
20
+
21
+ # 镜像权限处理
22
  RUN chmod -R 777 /app
23
 
24
  EXPOSE 7860
25
 
26
  # 使用直接启动模式
27
+ CMD ["python", "app.py"]
app.py CHANGED
@@ -1,25 +1,34 @@
1
  import builtins
2
  import os
 
3
  import shutil
4
  import io
5
  import time
6
  import uvicorn
7
  from fastapi import FastAPI, UploadFile, File, Form, HTTPException
8
  from fastapi.responses import StreamingResponse
9
- from huggingface_hub import snapshot_download
10
 
11
  # 🔴 核心:在所有 import 之前,必须先劫持 input
12
  builtins.input = lambda prompt="": "y"
 
 
 
 
 
 
 
13
  # 适配 Space 路径,本地运行时请确保此目录存在
14
  os.environ["GENIE_DATA_DIR"] = "/app/GenieData"
15
 
16
- # 下载环境
17
- if not os.path.exists("/app/GenieData/G2P"):
18
- print("📦 Downloading GenieData Assets...")
19
- snapshot_download(repo_id="High-Logic/Genie", allow_patterns=["GenieData/*"], local_dir="/app", local_dir_use_symlinks=False)
 
20
 
21
  import genie_tts
22
 
 
23
  app = FastAPI()
24
 
25
  # 角色模型存放根目录
 
1
  import builtins
2
  import os
3
+ import sys
4
  import shutil
5
  import io
6
  import time
7
  import uvicorn
8
  from fastapi import FastAPI, UploadFile, File, Form, HTTPException
9
  from fastapi.responses import StreamingResponse
 
10
 
11
  # 🔴 核心:在所有 import 之前,必须先劫持 input
12
  builtins.input = lambda prompt="": "y"
13
+
14
+ # 使用本地 genie_tts 源码(而非已安装的包)
15
+ # 将当前目录添加到 sys.path,确保优先加载本地模块
16
+ current_dir = os.path.dirname(os.path.abspath(__file__))
17
+ if current_dir not in sys.path:
18
+ sys.path.insert(0, current_dir)
19
+
20
  # 适配 Space 路径,本地运行时请确保此目录存在
21
  os.environ["GENIE_DATA_DIR"] = "/app/GenieData"
22
 
23
+ # 注释掉自动下载逻辑,假设 GenieData 已预装在镜像中
24
+ # if not os.path.exists("/app/GenieData/G2P"):
25
+ # print("📦 Downloading GenieData Assets...")
26
+ # from huggingface_hub import snapshot_download
27
+ # snapshot_download(repo_id="High-Logic/Genie", allow_patterns=["GenieData/*"], local_dir="/app", local_dir_use_symlinks=False)
28
 
29
  import genie_tts
30
 
31
+
32
  app = FastAPI()
33
 
34
  # 角色模型存放根目录