Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
import os
|
| 2 |
import sys
|
| 3 |
-
import
|
| 4 |
|
| 5 |
# ==========================================
|
| 6 |
-
# 1.
|
| 7 |
# ==========================================
|
| 8 |
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
|
| 9 |
import torch
|
|
@@ -15,44 +15,39 @@ torch.nn.Module.cuda = no_op
|
|
| 15 |
print("💉 CUDA 已屏蔽")
|
| 16 |
|
| 17 |
# ==========================================
|
| 18 |
-
# 2.
|
| 19 |
# ==========================================
|
| 20 |
-
print("
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
if name in files:
|
| 25 |
-
return os.path.join(root, name)
|
| 26 |
-
return None
|
| 27 |
|
| 28 |
-
#
|
| 29 |
-
|
| 30 |
-
# 2. 找到目标文件 (GPU版)
|
| 31 |
-
gpu_dst = find_file("t2s_model_flash_attn.py")
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
|
| 39 |
-
#
|
| 40 |
-
|
| 41 |
-
|
|
|
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
# 🧹 清理 pycache 防止缓存作祟
|
| 47 |
-
cache_dir = os.path.join(os.path.dirname(gpu_dst), "__pycache__")
|
| 48 |
-
if os.path.exists(cache_dir):
|
| 49 |
-
shutil.rmtree(cache_dir)
|
| 50 |
-
print("🧹 已清理 __pycache__")
|
| 51 |
|
| 52 |
-
|
| 53 |
-
print(
|
| 54 |
-
else:
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
# ==========================================
|
| 58 |
# 3. 导入核心逻辑
|
|
@@ -63,14 +58,11 @@ try:
|
|
| 63 |
import inference_webui as core
|
| 64 |
print("✅ 成功导入 inference_webui")
|
| 65 |
|
| 66 |
-
# 强制修改配置
|
| 67 |
if hasattr(core, "is_half"): core.is_half = False
|
| 68 |
if hasattr(core, "device"): core.device = "cpu"
|
| 69 |
|
| 70 |
except Exception as e:
|
| 71 |
print(f"❌ 导入失败: {e}")
|
| 72 |
-
# 打印一下当前目录,方便排查
|
| 73 |
-
print(f"当前目录文件: {os.listdir('.')}")
|
| 74 |
sys.exit(1)
|
| 75 |
|
| 76 |
# ==========================================
|
|
@@ -93,9 +85,7 @@ sovits_path = find_model_file("s2Gv2ProPlus.pth") or find_model_file("s2G")
|
|
| 93 |
# ==========================================
|
| 94 |
try:
|
| 95 |
if gpt_path and sovits_path:
|
| 96 |
-
# 再次强制关闭半精度
|
| 97 |
core.is_half = False
|
| 98 |
-
|
| 99 |
if hasattr(core, "change_gpt_weights"):
|
| 100 |
core.change_gpt_weights(gpt_path=gpt_path)
|
| 101 |
if hasattr(core, "change_sovits_weights"):
|
|
@@ -149,13 +139,13 @@ def run_predict(text):
|
|
| 149 |
return None, f"💥 报错: {e}"
|
| 150 |
|
| 151 |
# ==========================================
|
| 152 |
-
# 7.
|
| 153 |
# ==========================================
|
| 154 |
with gr.Blocks() as app:
|
| 155 |
-
gr.Markdown(f"### GPT-SoVITS V2 (
|
| 156 |
|
| 157 |
with gr.Row():
|
| 158 |
-
inp = gr.Textbox(label="文本", value="
|
| 159 |
btn = gr.Button("生成")
|
| 160 |
|
| 161 |
with gr.Row():
|
|
|
|
| 1 |
import os
|
| 2 |
import sys
|
| 3 |
+
import requests
|
| 4 |
|
| 5 |
# ==========================================
|
| 6 |
+
# 1. 基础环境净化
|
| 7 |
# ==========================================
|
| 8 |
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
|
| 9 |
import torch
|
|
|
|
| 15 |
print("💉 CUDA 已屏蔽")
|
| 16 |
|
| 17 |
# ==========================================
|
| 18 |
+
# 2. 核心补丁:远程空投 CPU 代码
|
| 19 |
# ==========================================
|
| 20 |
+
print("📡 正在从官方仓库下载 CPU 版代码...")
|
| 21 |
|
| 22 |
+
# 官方 CPU 版代码的地址
|
| 23 |
+
CPU_CODE_URL = "https://raw.githubusercontent.com/RVC-Boss/GPT-SoVITS/main/GPT_SoVITS/AR/models/t2s_model.py"
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
# 本地要覆盖的目标文件 (那个报错的 GPU 文件)
|
| 26 |
+
target_path = "./AR/models/t2s_model_flash_attn.py"
|
|
|
|
|
|
|
| 27 |
|
| 28 |
+
try:
|
| 29 |
+
# 1. 下载代码
|
| 30 |
+
response = requests.get(CPU_CODE_URL, timeout=10)
|
| 31 |
+
if response.status_code == 200:
|
| 32 |
+
cpu_code = response.text
|
| 33 |
|
| 34 |
+
# 2. 覆盖写入
|
| 35 |
+
if os.path.exists(target_path):
|
| 36 |
+
# 备份一下是个好习惯,虽然我们不需要备份
|
| 37 |
+
os.rename(target_path, target_path + ".bak")
|
| 38 |
|
| 39 |
+
with open(target_path, "w", encoding="utf-8") as f:
|
| 40 |
+
f.write(cpu_code)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
+
print(f"✅ 空投成功!已将 CPU 代码写入: {target_path}")
|
| 43 |
+
print("现在系统运行这个文件时,实际上跑的是官方 CPU 逻辑。")
|
| 44 |
+
else:
|
| 45 |
+
print(f"❌ 下载失败: HTTP {response.status_code}")
|
| 46 |
+
# 如果下载失败,尝试手动写入一段最小化的 Mock 代码防止 crash
|
| 47 |
+
# (略,赌下载能成功)
|
| 48 |
+
|
| 49 |
+
except Exception as e:
|
| 50 |
+
print(f"❌ 空投过程出错: {e}")
|
| 51 |
|
| 52 |
# ==========================================
|
| 53 |
# 3. 导入核心逻辑
|
|
|
|
| 58 |
import inference_webui as core
|
| 59 |
print("✅ 成功导入 inference_webui")
|
| 60 |
|
|
|
|
| 61 |
if hasattr(core, "is_half"): core.is_half = False
|
| 62 |
if hasattr(core, "device"): core.device = "cpu"
|
| 63 |
|
| 64 |
except Exception as e:
|
| 65 |
print(f"❌ 导入失败: {e}")
|
|
|
|
|
|
|
| 66 |
sys.exit(1)
|
| 67 |
|
| 68 |
# ==========================================
|
|
|
|
| 85 |
# ==========================================
|
| 86 |
try:
|
| 87 |
if gpt_path and sovits_path:
|
|
|
|
| 88 |
core.is_half = False
|
|
|
|
| 89 |
if hasattr(core, "change_gpt_weights"):
|
| 90 |
core.change_gpt_weights(gpt_path=gpt_path)
|
| 91 |
if hasattr(core, "change_sovits_weights"):
|
|
|
|
| 139 |
return None, f"💥 报错: {e}"
|
| 140 |
|
| 141 |
# ==========================================
|
| 142 |
+
# 7. 界面
|
| 143 |
# ==========================================
|
| 144 |
with gr.Blocks() as app:
|
| 145 |
+
gr.Markdown(f"### GPT-SoVITS V2 (Remote Patch)")
|
| 146 |
|
| 147 |
with gr.Row():
|
| 148 |
+
inp = gr.Textbox(label="文本", value="这下真的真的真的要成功了。")
|
| 149 |
btn = gr.Button("生成")
|
| 150 |
|
| 151 |
with gr.Row():
|