Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import os
|
| 2 |
import sys
|
| 3 |
-
import shutil
|
| 4 |
import requests
|
|
|
|
| 5 |
|
| 6 |
# ==========================================
|
| 7 |
# 1. 基础环境净化
|
|
@@ -16,61 +16,56 @@ torch.nn.Module.cuda = no_op
|
|
| 16 |
print("💉 CUDA 已屏蔽")
|
| 17 |
|
| 18 |
# ==========================================
|
| 19 |
-
# 2.
|
| 20 |
# ==========================================
|
| 21 |
-
print("
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
for
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
print(f"
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
print("✅ 验证通过:文件头已变为 CPU 代码。")
|
| 66 |
-
|
| 67 |
-
except Exception as e:
|
| 68 |
-
print(f"❌ 覆盖失败 {full_path}: {e}")
|
| 69 |
-
|
| 70 |
-
if hit_count == 0:
|
| 71 |
-
print("⚠️ 警告:全盘扫描未发现目标文件!")
|
| 72 |
-
else:
|
| 73 |
-
print(f"🎉 共处理了 {hit_count} 个文件,清理了所有缓存。")
|
| 74 |
|
| 75 |
# ==========================================
|
| 76 |
# 3. 导入核心逻辑
|
|
@@ -80,8 +75,10 @@ sys.path.append(os.getcwd())
|
|
| 80 |
try:
|
| 81 |
import inference_webui as core
|
| 82 |
print("✅ 成功导入 inference_webui")
|
|
|
|
| 83 |
if hasattr(core, "is_half"): core.is_half = False
|
| 84 |
if hasattr(core, "device"): core.device = "cpu"
|
|
|
|
| 85 |
except Exception as e:
|
| 86 |
print(f"❌ 导入失败: {e}")
|
| 87 |
sys.exit(1)
|
|
@@ -111,7 +108,7 @@ try:
|
|
| 111 |
core.change_gpt_weights(gpt_path=gpt_path)
|
| 112 |
if hasattr(core, "change_sovits_weights"):
|
| 113 |
core.change_sovits_weights(sovits_path=sovits_path)
|
| 114 |
-
print(f"🎉 模型加载成功!(CPU
|
| 115 |
else:
|
| 116 |
print("❌ 未找到模型文件")
|
| 117 |
except Exception as e:
|
|
@@ -163,13 +160,16 @@ def run_predict(text):
|
|
| 163 |
# 7. 界面
|
| 164 |
# ==========================================
|
| 165 |
with gr.Blocks() as app:
|
| 166 |
-
gr.Markdown(f"### GPT-SoVITS V2 (
|
|
|
|
| 167 |
with gr.Row():
|
| 168 |
-
inp = gr.Textbox(label="文本", value="
|
| 169 |
btn = gr.Button("生成")
|
|
|
|
| 170 |
with gr.Row():
|
| 171 |
out = gr.Audio(label="结果")
|
| 172 |
log = gr.Textbox(label="日志")
|
|
|
|
| 173 |
btn.click(run_predict, [inp], [out, log], api_name="predict")
|
| 174 |
|
| 175 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import os
|
| 2 |
import sys
|
|
|
|
| 3 |
import requests
|
| 4 |
+
import shutil
|
| 5 |
|
| 6 |
# ==========================================
|
| 7 |
# 1. 基础环境净化
|
|
|
|
| 16 |
print("💉 CUDA 已屏蔽")
|
| 17 |
|
| 18 |
# ==========================================
|
| 19 |
+
# 2. 核心补丁:补全 CPU 缺失文件
|
| 20 |
# ==========================================
|
| 21 |
+
print("🏗️ 启动依赖补全计划...")
|
| 22 |
+
|
| 23 |
+
FILES_TO_PATCH = [
|
| 24 |
+
{
|
| 25 |
+
"url": "https://raw.githubusercontent.com/RVC-Boss/GPT-SoVITS/main/GPT_SoVITS/AR/models/t2s_model.py",
|
| 26 |
+
"path": "AR/models/t2s_model_flash_attn.py", # 覆盖目标
|
| 27 |
+
"desc": "模型主文件 (CPU替换GPU)"
|
| 28 |
+
},
|
| 29 |
+
{
|
| 30 |
+
"url": "https://raw.githubusercontent.com/RVC-Boss/GPT-SoVITS/main/GPT_SoVITS/AR/models/utils.py",
|
| 31 |
+
"path": "AR/models/utils.py",
|
| 32 |
+
"desc": "工具库 (Utils)"
|
| 33 |
+
},
|
| 34 |
+
{
|
| 35 |
+
"url": "https://raw.githubusercontent.com/RVC-Boss/GPT-SoVITS/main/GPT_SoVITS/AR/modules/embedding.py",
|
| 36 |
+
"path": "AR/modules/embedding.py",
|
| 37 |
+
"desc": "嵌入层 (Embedding)"
|
| 38 |
+
}
|
| 39 |
+
]
|
| 40 |
+
|
| 41 |
+
for item in FILES_TO_PATCH:
|
| 42 |
+
try:
|
| 43 |
+
# 1. 确保目录存在
|
| 44 |
+
dir_name = os.path.dirname(item["path"])
|
| 45 |
+
if not os.path.exists(dir_name):
|
| 46 |
+
os.makedirs(dir_name, exist_ok=True)
|
| 47 |
+
print(f"📁 创建目录: {dir_name}")
|
| 48 |
+
|
| 49 |
+
# 补一个 __init__.py 确保可导入
|
| 50 |
+
with open(os.path.join(dir_name, "__init__.py"), "w") as f: f.write("")
|
| 51 |
+
|
| 52 |
+
# 2. 下载文件
|
| 53 |
+
print(f"⬇️ 下载 {item['desc']} ...")
|
| 54 |
+
resp = requests.get(item["url"], timeout=10)
|
| 55 |
+
if resp.status_code == 200:
|
| 56 |
+
# 3. 写入文件
|
| 57 |
+
with open(item["path"], "w", encoding="utf-8") as f:
|
| 58 |
+
f.write(resp.text)
|
| 59 |
+
print(f"✅ 写入成功: {item['path']}")
|
| 60 |
+
else:
|
| 61 |
+
print(f"❌ 下载失败 {item['url']}: {resp.status_code}")
|
| 62 |
|
| 63 |
+
except Exception as e:
|
| 64 |
+
print(f"⚠️ 处理 {item['path']} 时出错: {e}")
|
| 65 |
+
|
| 66 |
+
# 补充根目录 AR 的 __init__.py
|
| 67 |
+
if os.path.exists("AR") and not os.path.exists("AR/__init__.py"):
|
| 68 |
+
with open("AR/__init__.py", "w") as f: f.write("")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
# ==========================================
|
| 71 |
# 3. 导入核心逻辑
|
|
|
|
| 75 |
try:
|
| 76 |
import inference_webui as core
|
| 77 |
print("✅ 成功导入 inference_webui")
|
| 78 |
+
|
| 79 |
if hasattr(core, "is_half"): core.is_half = False
|
| 80 |
if hasattr(core, "device"): core.device = "cpu"
|
| 81 |
+
|
| 82 |
except Exception as e:
|
| 83 |
print(f"❌ 导入失败: {e}")
|
| 84 |
sys.exit(1)
|
|
|
|
| 108 |
core.change_gpt_weights(gpt_path=gpt_path)
|
| 109 |
if hasattr(core, "change_sovits_weights"):
|
| 110 |
core.change_sovits_weights(sovits_path=sovits_path)
|
| 111 |
+
print(f"🎉 模型加载成功!(CPU Full Patch)")
|
| 112 |
else:
|
| 113 |
print("❌ 未找到模型文件")
|
| 114 |
except Exception as e:
|
|
|
|
| 160 |
# 7. 界面
|
| 161 |
# ==========================================
|
| 162 |
with gr.Blocks() as app:
|
| 163 |
+
gr.Markdown(f"### GPT-SoVITS V2 (CPU Full Repair)")
|
| 164 |
+
|
| 165 |
with gr.Row():
|
| 166 |
+
inp = gr.Textbox(label="文本", value="这下真的真的真的要成功了。")
|
| 167 |
btn = gr.Button("生成")
|
| 168 |
+
|
| 169 |
with gr.Row():
|
| 170 |
out = gr.Audio(label="结果")
|
| 171 |
log = gr.Textbox(label="日志")
|
| 172 |
+
|
| 173 |
btn.click(run_predict, [inp], [out, log], api_name="predict")
|
| 174 |
|
| 175 |
if __name__ == "__main__":
|