Spaces:
Build error
Build error
积极的屁孩
commited on
Commit
·
d202deb
1
Parent(s):
3df7acf
debug
Browse files
app.py
CHANGED
|
@@ -9,6 +9,19 @@ import shutil
|
|
| 9 |
from huggingface_hub import snapshot_download, hf_hub_download
|
| 10 |
import requests
|
| 11 |
import subprocess
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
# 检查并安装必要的依赖
|
| 14 |
def install_dependencies():
|
|
@@ -100,6 +113,33 @@ def download_amphion_code():
|
|
| 100 |
if not os.path.exists(local_path):
|
| 101 |
with open(local_path, "w") as f:
|
| 102 |
f.write("# Placeholder file\n")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
# 先下载必要的代码文件
|
| 105 |
download_amphion_code()
|
|
@@ -159,10 +199,10 @@ class VevoGradioApp:
|
|
| 159 |
self.pipelines = {}
|
| 160 |
# 配置文件路径
|
| 161 |
self.config_paths = {
|
| 162 |
-
"vq32tovq8192": "./models/vc/vevo/config/Vq32ToVq8192.json",
|
| 163 |
-
"vq8192tomels": "./models/vc/vevo/config/Vq8192ToMels.json",
|
| 164 |
-
"phonetovq8192": "./models/vc/vevo/config/PhoneToVq8192.json",
|
| 165 |
-
"vocoder": "./models/vc/vevo/config/Vocoder.json"
|
| 166 |
}
|
| 167 |
|
| 168 |
# 确保配置文件存在
|
|
@@ -170,7 +210,8 @@ class VevoGradioApp:
|
|
| 170 |
|
| 171 |
def download_configs(self):
|
| 172 |
"""下载必要的配置文件"""
|
| 173 |
-
|
|
|
|
| 174 |
config_files = {
|
| 175 |
"Vq32ToVq8192.json": "https://raw.githubusercontent.com/open-mmlab/Amphion/main/models/vc/vevo/config/Vq32ToVq8192.json",
|
| 176 |
"Vq8192ToMels.json": "https://raw.githubusercontent.com/open-mmlab/Amphion/main/models/vc/vevo/config/Vq8192ToMels.json",
|
|
@@ -179,7 +220,7 @@ class VevoGradioApp:
|
|
| 179 |
}
|
| 180 |
|
| 181 |
for filename, url in config_files.items():
|
| 182 |
-
target_path =
|
| 183 |
if not os.path.exists(target_path):
|
| 184 |
try:
|
| 185 |
response = requests.get(url)
|
|
@@ -197,6 +238,31 @@ class VevoGradioApp:
|
|
| 197 |
with open(target_path, 'w') as f:
|
| 198 |
f.write('{}')
|
| 199 |
print(f"无法下载配置文件 {filename},已创建占位符")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
|
| 201 |
def init_voice_conversion_pipeline(self):
|
| 202 |
"""初始化语音转换管道"""
|
|
@@ -264,7 +330,16 @@ class VevoGradioApp:
|
|
| 264 |
except Exception as e:
|
| 265 |
print(f"初始化语音转换管道时出错: {str(e)}")
|
| 266 |
# 创建一个占位符管道
|
| 267 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 268 |
|
| 269 |
return self.pipelines["voice"]
|
| 270 |
|
|
@@ -311,7 +386,16 @@ class VevoGradioApp:
|
|
| 311 |
except Exception as e:
|
| 312 |
print(f"初始化音色转换管道时出错: {str(e)}")
|
| 313 |
# 创建一个占位符管道
|
| 314 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 315 |
|
| 316 |
return self.pipelines["timbre"]
|
| 317 |
|
|
@@ -369,7 +453,17 @@ class VevoGradioApp:
|
|
| 369 |
except Exception as e:
|
| 370 |
print(f"初始化TTS管道时出错: {str(e)}")
|
| 371 |
# 创建一个占位符管道
|
| 372 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 373 |
|
| 374 |
return self.pipelines["tts"]
|
| 375 |
|
|
|
|
| 9 |
from huggingface_hub import snapshot_download, hf_hub_download
|
| 10 |
import requests
|
| 11 |
import subprocess
|
| 12 |
+
import json
|
| 13 |
+
|
| 14 |
+
# 获取当前工作目录的绝对路径
|
| 15 |
+
BASE_DIR = os.path.abspath(os.getcwd())
|
| 16 |
+
|
| 17 |
+
# 修复相对路径为绝对路径的函数
|
| 18 |
+
def fix_path(path):
|
| 19 |
+
if path is None:
|
| 20 |
+
return None
|
| 21 |
+
# 如果是相对路径(以./开头),转换为绝对路径
|
| 22 |
+
if isinstance(path, str) and path.startswith('./'):
|
| 23 |
+
return os.path.join(BASE_DIR, path[2:])
|
| 24 |
+
return path
|
| 25 |
|
| 26 |
# 检查并安装必要的依赖
|
| 27 |
def install_dependencies():
|
|
|
|
| 113 |
if not os.path.exists(local_path):
|
| 114 |
with open(local_path, "w") as f:
|
| 115 |
f.write("# Placeholder file\n")
|
| 116 |
+
|
| 117 |
+
# 下载特殊文件:hubert_large_l18_mean_std.npz
|
| 118 |
+
try:
|
| 119 |
+
# 确保目录存在
|
| 120 |
+
os.makedirs(os.path.join(os.getcwd(), "models/vc/vevo/config"), exist_ok=True)
|
| 121 |
+
|
| 122 |
+
# 尝试从HuggingFace下载
|
| 123 |
+
try:
|
| 124 |
+
hf_hub_download(
|
| 125 |
+
repo_id=REPO_ID,
|
| 126 |
+
filename="tokenizer/vq8192/hubert_large_l18_mean_std.npz",
|
| 127 |
+
cache_dir=CACHE_DIR,
|
| 128 |
+
local_dir=os.path.join(os.getcwd(), "models/vc/vevo/config"),
|
| 129 |
+
local_dir_use_symlinks=False
|
| 130 |
+
)
|
| 131 |
+
print("成功下载: hubert_large_l18_mean_std.npz")
|
| 132 |
+
except Exception as e:
|
| 133 |
+
print(f"无法从HuggingFace下载hubert_large_l18_mean_std.npz: {str(e)}")
|
| 134 |
+
# 尝试从GitHub下载
|
| 135 |
+
hubert_url = "https://huggingface.co/amphion/Vevo/resolve/main/tokenizer/vq8192/hubert_large_l18_mean_std.npz"
|
| 136 |
+
response = requests.get(hubert_url)
|
| 137 |
+
if response.status_code == 200:
|
| 138 |
+
with open(os.path.join(os.getcwd(), "models/vc/vevo/config/hubert_large_l18_mean_std.npz"), "wb") as f:
|
| 139 |
+
f.write(response.content)
|
| 140 |
+
print("成功从HuggingFace下载: hubert_large_l18_mean_std.npz")
|
| 141 |
+
except Exception as e:
|
| 142 |
+
print(f"下载hubert_large_l18_mean_std.npz时出错: {str(e)}")
|
| 143 |
|
| 144 |
# 先下载必要的代码文件
|
| 145 |
download_amphion_code()
|
|
|
|
| 199 |
self.pipelines = {}
|
| 200 |
# 配置文件路径
|
| 201 |
self.config_paths = {
|
| 202 |
+
"vq32tovq8192": fix_path("./models/vc/vevo/config/Vq32ToVq8192.json"),
|
| 203 |
+
"vq8192tomels": fix_path("./models/vc/vevo/config/Vq8192ToMels.json"),
|
| 204 |
+
"phonetovq8192": fix_path("./models/vc/vevo/config/PhoneToVq8192.json"),
|
| 205 |
+
"vocoder": fix_path("./models/vc/vevo/config/Vocoder.json")
|
| 206 |
}
|
| 207 |
|
| 208 |
# 确保配置文件存在
|
|
|
|
| 210 |
|
| 211 |
def download_configs(self):
|
| 212 |
"""下载必要的配置文件"""
|
| 213 |
+
config_dir = fix_path("./models/vc/vevo/config")
|
| 214 |
+
os.makedirs(config_dir, exist_ok=True)
|
| 215 |
config_files = {
|
| 216 |
"Vq32ToVq8192.json": "https://raw.githubusercontent.com/open-mmlab/Amphion/main/models/vc/vevo/config/Vq32ToVq8192.json",
|
| 217 |
"Vq8192ToMels.json": "https://raw.githubusercontent.com/open-mmlab/Amphion/main/models/vc/vevo/config/Vq8192ToMels.json",
|
|
|
|
| 220 |
}
|
| 221 |
|
| 222 |
for filename, url in config_files.items():
|
| 223 |
+
target_path = os.path.join(config_dir, filename)
|
| 224 |
if not os.path.exists(target_path):
|
| 225 |
try:
|
| 226 |
response = requests.get(url)
|
|
|
|
| 238 |
with open(target_path, 'w') as f:
|
| 239 |
f.write('{}')
|
| 240 |
print(f"无法下载配置文件 {filename},已创建占位符")
|
| 241 |
+
|
| 242 |
+
# 修改配置文件中的相对路径
|
| 243 |
+
self.update_config_paths()
|
| 244 |
+
|
| 245 |
+
def update_config_paths(self):
|
| 246 |
+
"""修改配置文件中的相对路径"""
|
| 247 |
+
try:
|
| 248 |
+
# 修改Vq8192ToMels.json文件中的路径引用
|
| 249 |
+
vq8192_path = self.config_paths["vq8192tomels"]
|
| 250 |
+
if os.path.exists(vq8192_path):
|
| 251 |
+
with open(vq8192_path, 'r') as f:
|
| 252 |
+
config = json.load(f)
|
| 253 |
+
|
| 254 |
+
# 修改hubert_large_l18_mean_std.npz路径
|
| 255 |
+
if "model" in config and "representation_stat_mean_var_path" in config["model"]:
|
| 256 |
+
# 替换为绝对路径
|
| 257 |
+
hubert_stat_path = fix_path("./models/vc/vevo/config/hubert_large_l18_mean_std.npz")
|
| 258 |
+
config["model"]["representation_stat_mean_var_path"] = hubert_stat_path
|
| 259 |
+
|
| 260 |
+
# 保存修改后的配置
|
| 261 |
+
with open(vq8192_path, 'w') as f:
|
| 262 |
+
json.dump(config, f, indent=2)
|
| 263 |
+
print("成功更新配置文件中的路径")
|
| 264 |
+
except Exception as e:
|
| 265 |
+
print(f"更新配置文件路径时出错: {str(e)}")
|
| 266 |
|
| 267 |
def init_voice_conversion_pipeline(self):
|
| 268 |
"""初始化语音转换管道"""
|
|
|
|
| 330 |
except Exception as e:
|
| 331 |
print(f"初始化语音转换管道时出错: {str(e)}")
|
| 332 |
# 创建一个占位符管道
|
| 333 |
+
try:
|
| 334 |
+
# 尝试提供必要的配置文件
|
| 335 |
+
self.pipelines["voice"] = VevoInferencePipeline(
|
| 336 |
+
device=self.device,
|
| 337 |
+
fmt_cfg_path=self.config_paths["vq8192tomels"],
|
| 338 |
+
vocoder_cfg_path=self.config_paths["vocoder"],
|
| 339 |
+
)
|
| 340 |
+
except:
|
| 341 |
+
# 如果还是失败,创建最简单的管道
|
| 342 |
+
self.pipelines["voice"] = VevoInferencePipeline(device=self.device)
|
| 343 |
|
| 344 |
return self.pipelines["voice"]
|
| 345 |
|
|
|
|
| 386 |
except Exception as e:
|
| 387 |
print(f"初始化音色转换管道时出错: {str(e)}")
|
| 388 |
# 创建一个占位符管道
|
| 389 |
+
try:
|
| 390 |
+
# 尝试提供必要的配置文件
|
| 391 |
+
self.pipelines["timbre"] = VevoInferencePipeline(
|
| 392 |
+
device=self.device,
|
| 393 |
+
fmt_cfg_path=self.config_paths["vq8192tomels"],
|
| 394 |
+
vocoder_cfg_path=self.config_paths["vocoder"],
|
| 395 |
+
)
|
| 396 |
+
except:
|
| 397 |
+
# 如果还是失败,创建最简单的管道
|
| 398 |
+
self.pipelines["timbre"] = VevoInferencePipeline(device=self.device)
|
| 399 |
|
| 400 |
return self.pipelines["timbre"]
|
| 401 |
|
|
|
|
| 453 |
except Exception as e:
|
| 454 |
print(f"初始化TTS管道时出错: {str(e)}")
|
| 455 |
# 创建一个占位符管道
|
| 456 |
+
try:
|
| 457 |
+
# 尝试提供必要的配置文件
|
| 458 |
+
self.pipelines["tts"] = VevoInferencePipeline(
|
| 459 |
+
device=self.device,
|
| 460 |
+
fmt_cfg_path=self.config_paths["vq8192tomels"],
|
| 461 |
+
vocoder_cfg_path=self.config_paths["vocoder"],
|
| 462 |
+
ar_cfg_path=self.config_paths["phonetovq8192"],
|
| 463 |
+
)
|
| 464 |
+
except:
|
| 465 |
+
# 如果还是失败,创建最简单的管道
|
| 466 |
+
self.pipelines["tts"] = VevoInferencePipeline(device=self.device)
|
| 467 |
|
| 468 |
return self.pipelines["tts"]
|
| 469 |
|