Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,80 +4,63 @@ import subprocess
|
|
| 4 |
import uuid
|
| 5 |
import shutil
|
| 6 |
|
| 7 |
-
# --- 1. 赛博雅韵 UI
|
| 8 |
shensist_theme = gr.themes.Base(primary_hue="indigo").set(
|
| 9 |
body_background_fill="*neutral_950",
|
| 10 |
block_background_fill="*neutral_900",
|
| 11 |
)
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
# 全
|
| 24 |
vocal_path = None
|
| 25 |
-
for root, _, files in os.walk(
|
| 26 |
if "vocals.wav" in files:
|
| 27 |
vocal_path = os.path.join(root, "vocals.wav")
|
| 28 |
break
|
| 29 |
|
| 30 |
if vocal_path:
|
| 31 |
-
#
|
| 32 |
-
|
| 33 |
-
shutil.copy(vocal_path,
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
agent = ShensistAgent()
|
| 38 |
-
|
| 39 |
-
def shensist_agent_sing(audio_path, history):
|
| 40 |
-
if history is None: history = []
|
| 41 |
-
|
| 42 |
-
# [节点 1: 指令拦截]
|
| 43 |
-
history.append({"role": "user", "content": "激活智能体。要求:剥离伴奏,输出纯净清唱。"})
|
| 44 |
-
yield history, gr.MultimodalTextbox(interactive=False)
|
| 45 |
-
|
| 46 |
-
# [节点 2: 后台提纯]
|
| 47 |
-
history.append({"role": "assistant", "content": "🔵 [天算代理] 正在启动 UVR 核心,强制执行伴奏剥离..."})
|
| 48 |
-
yield history, gr.MultimodalTextbox(interactive=False)
|
| 49 |
-
|
| 50 |
-
try:
|
| 51 |
-
# 执行核心工作流
|
| 52 |
-
vocal_file = agent.process_acappella(audio_path)
|
| 53 |
-
|
| 54 |
-
if vocal_file:
|
| 55 |
-
history.pop() # 移除加载中消息
|
| 56 |
history.append({
|
| 57 |
"role": "assistant",
|
| 58 |
-
"content": "【神思庭·灵愿完成】\n伴奏已彻底剔除。这是为您重
|
| 59 |
})
|
| 60 |
-
#
|
| 61 |
-
history.append({"role": "assistant", "content": gr.Audio(
|
| 62 |
else:
|
| 63 |
-
raise FileNotFoundError("
|
| 64 |
|
| 65 |
except Exception as e:
|
| 66 |
if history: history.pop()
|
| 67 |
-
history.append({"role": "assistant", "content": f"🔴 算力
|
| 68 |
|
| 69 |
-
yield history
|
| 70 |
|
| 71 |
-
|
| 72 |
-
with gr.Blocks(title="神思庭 | AI A Cappella 代理") as demo:
|
| 73 |
gr.Markdown("# 🏛️ **神思庭 · AI A Cappella 代理**")
|
| 74 |
chatbot = gr.Chatbot(label="超个体交互场域", height=600)
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
audio_input = gr.Audio(type="filepath", label="上传原曲")
|
| 78 |
-
submit_btn = gr.Button("激活代理", variant="primary")
|
| 79 |
-
|
| 80 |
-
submit_btn.click(shensist_agent_sing, [audio_input, chatbot], [chatbot, audio_input])
|
| 81 |
|
| 82 |
if __name__ == "__main__":
|
| 83 |
-
demo.queue().launch(
|
|
|
|
| 4 |
import uuid
|
| 5 |
import shutil
|
| 6 |
|
| 7 |
+
# --- 1. 赛博雅韵 UI (符合神思庭美学) ---
|
| 8 |
shensist_theme = gr.themes.Base(primary_hue="indigo").set(
|
| 9 |
body_background_fill="*neutral_950",
|
| 10 |
block_background_fill="*neutral_900",
|
| 11 |
)
|
| 12 |
|
| 13 |
+
def shensist_agent_pure_vocal(audio_path, history):
|
| 14 |
+
if history is None: history = []
|
| 15 |
+
|
| 16 |
+
# [节点 1: 拦截并确认意图]
|
| 17 |
+
history.append({"role": "user", "content": "激活智能体:请剥离伴奏,交付纯净清唱干音。"})
|
| 18 |
+
yield history
|
| 19 |
+
|
| 20 |
+
# [节点 2: 后台强制剥离]
|
| 21 |
+
history.append({"role": "assistant", "content": "🔵 [天算代理] 正在启动 UVR 核心逻辑,进行资产提纯..."})
|
| 22 |
+
yield history
|
| 23 |
+
|
| 24 |
+
try:
|
| 25 |
+
output_dir = os.path.abspath("./agent_output")
|
| 26 |
+
if os.path.exists(output_dir): shutil.rmtree(output_dir)
|
| 27 |
+
|
| 28 |
+
# 调用命令行分离引擎
|
| 29 |
+
subprocess.run(["demucs", "--two-stems", "vocals", audio_path, "-o", output_dir], check=True)
|
| 30 |
|
| 31 |
+
# --- 核心修复:全路径嗅探与资产搬运 ---
|
| 32 |
vocal_path = None
|
| 33 |
+
for root, _, files in os.walk(output_dir):
|
| 34 |
if "vocals.wav" in files:
|
| 35 |
vocal_path = os.path.join(root, "vocals.wav")
|
| 36 |
break
|
| 37 |
|
| 38 |
if vocal_path:
|
| 39 |
+
# 强制提取到根目录,确保 100% 能下载和播放
|
| 40 |
+
final_vocal = f"Shensist_Vocal_{uuid.uuid4().hex[:6]}.wav"
|
| 41 |
+
shutil.copy(vocal_path, final_vocal)
|
| 42 |
+
|
| 43 |
+
history.pop() # 移除加载状态
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
history.append({
|
| 45 |
"role": "assistant",
|
| 46 |
+
"content": "【神思庭·灵愿完成】\n伴奏已彻底剔除。这是为您重构的纯净清唱资产。\n\n🧠 天算AI · 超个体构建者\n◼️ 官网|shensist.top",
|
| 47 |
})
|
| 48 |
+
# 明确对象,激活播放器
|
| 49 |
+
history.append({"role": "assistant", "content": gr.Audio(final_vocal, label="AI A Cappella 流")})
|
| 50 |
else:
|
| 51 |
+
raise FileNotFoundError("引擎已运行,但人声资产未降临。")
|
| 52 |
|
| 53 |
except Exception as e:
|
| 54 |
if history: history.pop()
|
| 55 |
+
history.append({"role": "assistant", "content": f"🔴 算力中断:{str(e)}"})
|
| 56 |
|
| 57 |
+
yield history
|
| 58 |
|
| 59 |
+
with gr.Blocks(theme=shensist_theme, title="神思庭 | AI A Cappella 代理") as demo:
|
|
|
|
| 60 |
gr.Markdown("# 🏛️ **神思庭 · AI A Cappella 代理**")
|
| 61 |
chatbot = gr.Chatbot(label="超个体交互场域", height=600)
|
| 62 |
+
audio_input = gr.Audio(type="filepath", label="上传原曲")
|
| 63 |
+
audio_input.change(shensist_agent_pure_vocal, [audio_input, chatbot], [chatbot])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
if __name__ == "__main__":
|
| 66 |
+
demo.queue().launch()
|