ccyyss commited on
Commit
d932265
·
verified ·
1 Parent(s): ea4ccbd

deploy DeepFilterNet denoise app

Browse files
Files changed (3) hide show
  1. README.md +4 -4
  2. app.py +45 -59
  3. requirements.txt +1 -2
README.md CHANGED
@@ -1,13 +1,13 @@
1
  ---
2
- title: Ff
3
- emoji: 🐢
4
  colorFrom: green
5
  colorTo: blue
6
  sdk: gradio
7
  sdk_version: 6.19.0
8
- python_version: '3.13'
9
  app_file: app.py
10
  pinned: false
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: 音频降噪增强
3
+ emoji: 🎧
4
  colorFrom: green
5
  colorTo: blue
6
  sdk: gradio
7
  sdk_version: 6.19.0
8
+ python_version: 3.13
9
  app_file: app.py
10
  pinned: false
11
  ---
12
 
13
+ 基于 DeepFilterNet2 的人声降噪增强:上传带噪录音,下载干净版 wav。
app.py CHANGED
@@ -1,67 +1,53 @@
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
- from playwright.sync_api import sync_playwright
3
- from PIL import Image
4
- import io
5
- import subprocess
6
- import sys
7
- import os
8
 
9
- # ==================== 自动安装浏览器 ====================
10
- def install_browsers():
11
- print("Downloading Playwright browsers...")
12
- try:
13
- subprocess.run(["playwright", "install", "chromium", "--with-deps"], check=True)
14
- print("Browser installation completed!")
15
- except Exception as e:
16
- print(f"Browser install failed: {e}")
 
 
 
17
 
18
- if "SPACE_ID" in os.environ: # HF Space 环境
19
- install_browsers()
20
 
21
- # ==================== 主函数 ====================
22
- def run_automation(url: str, action: str = "screenshot"):
23
- try:
24
- with sync_playwright() as p:
25
- browser = p.chromium.launch(headless=True)
26
- page = browser.new_page(viewport={"width": 1280, "height": 720})
27
- page.goto(url, wait_until="networkidle", timeout=60000)
28
-
29
- if action == "screenshot":
30
- screenshot_bytes = page.screenshot(full_page=True)
31
- browser.close()
32
- image = Image.open(io.BytesIO(screenshot_bytes))
33
- return "✅ 截图成功!", image
34
- else:
35
- title = page.title()
36
- browser.close()
37
- return f"📄 页面标题:{title}", None
38
-
39
- except Exception as e:
40
- return f"❌ 错误:{str(e)}", None
41
 
42
- # ==================== Gradio 界面 ====================
43
- with gr.Blocks(title="网页截图工具") as demo:
44
- gr.Markdown("# 🌐 网页自动化演示(Playwright)")
45
-
46
- with gr.Row():
47
- url_input = gr.Textbox(
48
- label="网址",
49
- placeholder="https://huggingface.co",
50
- value="https://example.com",
51
- scale=4
52
- )
53
- action = gr.Radio(["screenshot", "title"], label="操作", value="screenshot")
54
-
55
- btn = gr.Button("🚀 执行", variant="primary")
56
-
57
- with gr.Row():
58
- output_text = gr.Textbox(label="状态")
59
- output_image = gr.Image(label="截图结果")
60
 
61
- btn.click(
62
- fn=run_automation,
63
- inputs=[url_input, action],
64
- outputs=[output_text, output_image]
 
 
 
 
 
 
 
 
 
65
  )
 
 
 
 
 
66
 
67
- demo.launch()
 
 
1
+ #!/usr/bin/env python3
2
+ """音频降噪增强:DeepFilterNet2 人声增强。
3
+
4
+ 上传带噪音频(口播、讲座录音等),输出降噪后的 wav。
5
+ 模型在首次请求时加载并缓存,之后常驻内存。
6
+ """
7
+ import threading
8
+
9
  import gradio as gr
 
 
 
 
 
 
10
 
11
+ _lock = threading.Lock()
12
+ _model = None
13
+ _df_state = None
14
+
15
+
16
+ def get_model():
17
+ global _model, _df_state
18
+ if _model is None:
19
+ with _lock:
20
+ if _model is None:
21
+ from df.enhance import init_df
22
 
23
+ _model, _df_state, _ = init_df()
24
+ return _model, _df_state
25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
+ def denoise(audio_path):
28
+ if not audio_path:
29
+ return None
30
+ from df.enhance import enhance, load_audio, save_audio
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
+ model, df_state = get_model()
33
+ audio, _ = load_audio(audio_path, sr=df_state.sr())
34
+ enhanced = enhance(model, df_state, audio)
35
+ out = "/tmp/enhanced.wav"
36
+ save_audio(out, enhanced, df_state.sr())
37
+ return out
38
+
39
+
40
+ with gr.Blocks(title="音频降噪增强") as demo:
41
+ gr.Markdown(
42
+ "# 🎧 音频降噪增强\n"
43
+ "基于 DeepFilterNet2 的人声降噪:上传带底噪、环境声的录音,输出干净版 wav(48kHz)。\n\n"
44
+ "适合口播、讲座这类以人声为主的素材。CPU 推理,长音频请按时长耐心等。"
45
  )
46
+ inp = gr.Audio(label="原始音频", type="filepath")
47
+ btn = gr.Button("开始降噪", variant="primary")
48
+ out = gr.Audio(label="降噪后", type="filepath")
49
+ btn.click(denoise, inputs=inp, outputs=out)
50
+
51
 
52
+ if __name__ == "__main__":
53
+ demo.launch()
requirements.txt CHANGED
@@ -1,2 +1 @@
1
- gradio>=5.0
2
- playwright
 
1
+ deepfilternet==0.5.6