Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,25 +16,43 @@ torch.nn.Module.cuda = no_op
|
|
| 16 |
print("💉 CUDA 已屏蔽")
|
| 17 |
|
| 18 |
# ==========================================
|
| 19 |
-
# 2.
|
| 20 |
# ==========================================
|
| 21 |
-
print("
|
| 22 |
|
|
|
|
|
|
|
|
|
|
| 23 |
FILES_TO_PATCH = [
|
|
|
|
| 24 |
{
|
| 25 |
-
"url": "
|
| 26 |
-
"path": "AR/models/t2s_model_flash_attn.py",
|
| 27 |
-
"desc": "模型主文件 (CPU替换GPU)"
|
| 28 |
},
|
|
|
|
| 29 |
{
|
| 30 |
-
"url": "
|
| 31 |
"path": "AR/models/utils.py",
|
| 32 |
-
"desc": "工具库 (Utils)"
|
| 33 |
},
|
|
|
|
| 34 |
{
|
| 35 |
-
"url": "
|
| 36 |
"path": "AR/modules/embedding.py",
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
}
|
| 39 |
]
|
| 40 |
|
|
@@ -44,26 +62,23 @@ for item in FILES_TO_PATCH:
|
|
| 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 |
-
|
| 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['
|
| 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"✅
|
| 60 |
else:
|
| 61 |
-
print(f"❌ 下载失败 {item['url']}
|
| 62 |
|
| 63 |
except Exception as e:
|
| 64 |
-
print(f"⚠️ 处理
|
| 65 |
|
| 66 |
-
# 补充根目录
|
| 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 |
|
|
@@ -108,7 +123,7 @@ try:
|
|
| 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
|
| 112 |
else:
|
| 113 |
print("❌ 未找到模型文件")
|
| 114 |
except Exception as e:
|
|
@@ -160,16 +175,13 @@ def run_predict(text):
|
|
| 160 |
# 7. 界面
|
| 161 |
# ==========================================
|
| 162 |
with gr.Blocks() as app:
|
| 163 |
-
gr.Markdown(f"### GPT-SoVITS V2 (
|
| 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__":
|
|
|
|
| 16 |
print("💉 CUDA 已屏蔽")
|
| 17 |
|
| 18 |
# ==========================================
|
| 19 |
+
# 2. 饱和式救援:下载全套缺失零件
|
| 20 |
# ==========================================
|
| 21 |
+
print("🚚 启动饱和式空投,正在重建 CPU 环境...")
|
| 22 |
|
| 23 |
+
BASE_URL = "https://raw.githubusercontent.com/RVC-Boss/GPT-SoVITS/main/GPT_SoVITS"
|
| 24 |
+
|
| 25 |
+
# 定义所有需要修复的文件清单
|
| 26 |
FILES_TO_PATCH = [
|
| 27 |
+
# 核心:把 CPU 模型代码写入 GPU 文件
|
| 28 |
{
|
| 29 |
+
"url": f"{BASE_URL}/AR/models/t2s_model.py",
|
| 30 |
+
"path": "AR/models/t2s_model_flash_attn.py",
|
|
|
|
| 31 |
},
|
| 32 |
+
# 依赖 1: Utils
|
| 33 |
{
|
| 34 |
+
"url": f"{BASE_URL}/AR/models/utils.py",
|
| 35 |
"path": "AR/models/utils.py",
|
|
|
|
| 36 |
},
|
| 37 |
+
# 依赖 2: Embedding
|
| 38 |
{
|
| 39 |
+
"url": f"{BASE_URL}/AR/modules/embedding.py",
|
| 40 |
"path": "AR/modules/embedding.py",
|
| 41 |
+
},
|
| 42 |
+
# 依赖 3: Transformer (你刚刚报错缺这个)
|
| 43 |
+
{
|
| 44 |
+
"url": f"{BASE_URL}/AR/modules/transformer.py",
|
| 45 |
+
"path": "AR/modules/transformer.py",
|
| 46 |
+
},
|
| 47 |
+
# 依赖 4: Attention (为了防止还没报错就先补上)
|
| 48 |
+
{
|
| 49 |
+
"url": f"{BASE_URL}/AR/modules/attention.py",
|
| 50 |
+
"path": "AR/modules/attention.py",
|
| 51 |
+
},
|
| 52 |
+
# 依赖 5: Commons (保险起见)
|
| 53 |
+
{
|
| 54 |
+
"url": f"{BASE_URL}/AR/modules/commons.py",
|
| 55 |
+
"path": "AR/modules/commons.py",
|
| 56 |
}
|
| 57 |
]
|
| 58 |
|
|
|
|
| 62 |
dir_name = os.path.dirname(item["path"])
|
| 63 |
if not os.path.exists(dir_name):
|
| 64 |
os.makedirs(dir_name, exist_ok=True)
|
| 65 |
+
# 补 init
|
|
|
|
|
|
|
| 66 |
with open(os.path.join(dir_name, "__init__.py"), "w") as f: f.write("")
|
| 67 |
|
| 68 |
+
# 2. 下载
|
| 69 |
+
print(f"⬇️ 下载补丁: {os.path.basename(item['path'])} ...")
|
| 70 |
resp = requests.get(item["url"], timeout=10)
|
| 71 |
if resp.status_code == 200:
|
|
|
|
| 72 |
with open(item["path"], "w", encoding="utf-8") as f:
|
| 73 |
f.write(resp.text)
|
| 74 |
+
print(f"✅ 修复成功: {item['path']}")
|
| 75 |
else:
|
| 76 |
+
print(f"❌ 下载失败 ({resp.status_code}): {item['url']}")
|
| 77 |
|
| 78 |
except Exception as e:
|
| 79 |
+
print(f"⚠️ 文件处理错误: {e}")
|
| 80 |
|
| 81 |
+
# 补充根目录 init
|
| 82 |
if os.path.exists("AR") and not os.path.exists("AR/__init__.py"):
|
| 83 |
with open("AR/__init__.py", "w") as f: f.write("")
|
| 84 |
|
|
|
|
| 123 |
core.change_gpt_weights(gpt_path=gpt_path)
|
| 124 |
if hasattr(core, "change_sovits_weights"):
|
| 125 |
core.change_sovits_weights(sovits_path=sovits_path)
|
| 126 |
+
print(f"🎉 模型加载成功!(CPU Rebuilt)")
|
| 127 |
else:
|
| 128 |
print("❌ 未找到模型文件")
|
| 129 |
except Exception as e:
|
|
|
|
| 175 |
# 7. 界面
|
| 176 |
# ==========================================
|
| 177 |
with gr.Blocks() as app:
|
| 178 |
+
gr.Markdown(f"### GPT-SoVITS V2 (Full Repair)")
|
|
|
|
| 179 |
with gr.Row():
|
| 180 |
+
inp = gr.Textbox(label="文本", value="所有零件都补齐了,这次一定行。")
|
| 181 |
btn = gr.Button("生成")
|
|
|
|
| 182 |
with gr.Row():
|
| 183 |
out = gr.Audio(label="结果")
|
| 184 |
log = gr.Textbox(label="日志")
|
|
|
|
| 185 |
btn.click(run_predict, [inp], [out, log], api_name="predict")
|
| 186 |
|
| 187 |
if __name__ == "__main__":
|