import gradio as gr
import torch
from DPTNet_eval.DPTNet_quant_sep import load_dpt_model, dpt_sep_process
# 加載模型
model = load_dpt_model()
def separate_audio(input_wav):
outfilename = "output.wav"
dpt_sep_process(input_wav, model=model, outfilename=outfilename)
return (
outfilename.replace('.wav', '_sep1.wav'),
outfilename.replace('.wav', '_sep2.wav')
)
# 🎯 你提供的 description 內容(已轉為 HTML)
description_html = """
上傳一段混音音檔,自動分離出兩個人的聲音
### 🔍 使用方式:
- 上傳一段包含兩人對話的混音音檔(支援 `.mp3`, `.wav`)
- 點擊「Separate」按鈕
- 分離出兩個說話人的音軌
### 📘 相關技術文章:
📢 *本模型基於 PyTorch + Hugging Face Hub 私有模型部署*
"""
# 📋 你提供的 examples(可替換成你自己的測試音檔)
examples = [
["examples/sample1.wav"], # 替換成你的音檔路徑
["examples/sample2.mp3"],
]
if __name__ == "__main__":
interface = gr.Interface(
fn=separate_audio,
inputs=gr.Audio(type="filepath", label="請上傳混音音檔 (.mp3/.wav)"),
outputs=[
gr.Audio(label="語音 1"),
gr.Audio(label="語音 2")
],
title="🎙️ 語音分離 Demo - Deep Learning 101",
description=description_html,
examples=examples,
allow_flagging="never"
)
interface.launch()