Skip to content

交互式应用 📤

Gradio 是一个用于快速搭建机器学习模型、脚本或工具交互界面的开源库,支持网页展示、分享链接、组件拖拽等功能,非常适合用来做可视化演示或测试。

使用场景

场景1:我想录制声音,还得人声分离,怎么办?

1. 定义应用

python
def separate_audio(input):
    # code ...
    return separated_vocals, separated_bg

def init():
    import gradio as gr

    return gr.Interface(
        fn=separate_audio,
        inputs=[
            gr.Audio(type="filepath", label="音频"),
            gr.Dropdown(choices=available_models(), label="模型", value="htdemucs"),
            gr.Slider(minimum=0, maximum=5, step=0.1, label="降噪", value=0),
            gr.Checkbox(label="调试", value=False),
        ],
        outputs=[
            gr.Audio(type="filepath", label="人声"),
            gr.Audio(type="filepath", label="伴奏"),
        ],
        title="CreatorBox - Voice Noise Separation",
    )

if __name__ == "__main__":
    init().launch(server_name="0.0.0.0", server_port=8000)

2. 注册应用

bash
curl -X 'POST' \
  'http://172.18.0.1:8000/gradio/mounts' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "name": "vns",
  "description": "Voice Noise Separation",
  "module": "src.support.vns_",
  "attr": "gradio",
  "path": "/vns",
  "status": 1
}'
request.json
json
{
   "name": "vns",                                # 名称
    "description": "Voice Noise Separation",     # 描述
    "module": "src.support.vns_",                # 路径
    "attr": "gradio",                            # 方法或变量名
    "path": "/vns",                              # 请求
    "status": 1                                  # 状态
}

3. 打开应用

应用列表

人声降噪分离

bash
curl -X 'POST' \
  'http://172.18.0.1:8000/gradio/mounts' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "name": "vns",
  "description": "Voice Noise Separation",
  "module": "src.support.vns_",
  "attr": "gradio",
  "path": "/vns",
  "status": 1
}'

视频标记去除

bash
curl -X 'POST' \
  'http://172.18.0.1:8000/gradio/mounts' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "name": "vmr",
  "description": "Video Marker Remove",
  "module": "src.support.vmr_",
  "attr": "gradio",
  "path": "/vmr",
  "status": 1
}'

视频字幕提取

bash
curl -X 'POST' \
  'http://172.18.0.1:8000/gradio/mounts' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "name": "vse",
  "description": "Video Subtitle Extractor",
  "module": "src.support.vse_",
  "attr": "gradio",
  "path": "/vse",
  "status": 1
}'