doevent commited on
Commit
6d72cca
·
1 Parent(s): 50bc605

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -0
app.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from tempfile import gettempdir
3
+ import gradio as gr
4
+ import subprocess
5
+ os.system("git clone https://github.com/doevent/FullSubNet-plus")
6
+ os.system("mv FullSubNet-plus/speech_enhance .")
7
+ os.system("mv FullSubNet-plus/config .")
8
+ os.system("gdown https://drive.google.com/uc?id=1UJSt1G0P_aXry-u79LLU_l9tCnNa2u7C -O best_model.tar")
9
+ from speech_enhance.tools.denoise_server import start
10
+
11
+
12
+ # If the file is too duration to inference
13
+ def duration(input_audio) -> int:
14
+ command = f"ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 -i {input_audio}"
15
+ result = subprocess.run(command, shell=True, stdout=subprocess.PIPE)
16
+ data = result.stdout.decode('ascii').rstrip()
17
+ return int(float(data))
18
+
19
+
20
+ def inference(audio):
21
+ try:
22
+ if duration(audio) >= 150:
23
+ return "error.wav"
24
+ result = start(to_list_files=[audio])
25
+ return result
26
+ except Exception as e:
27
+ return "error.wav"
28
+
29
+
30
+ title = """<h1 id="title">DeNoise Speech Enhancement</h1>"""
31
+ description = """
32
+ This is an unofficial demo for FullSubNet-plus: DeNoise Speech Enhancement. To use it, simply upload your audio, or click one of the examples to load them. Read more at the links below.
33
+ Link to GitHub:
34
+ - [FullSubNet +](https://github.com/hit-thusz-RookieCJ/FullSubNet-plus)
35
+ """
36
+ twitter_link = "[![](https://img.shields.io/twitter/follow/DoEvent?label=@DoEvent&style=social)](https://twitter.com/DoEvent)"
37
+ css = '''
38
+ h1#title {
39
+ text-align: center;
40
+ }
41
+ '''
42
+
43
+ demo = gr.Blocks(css=css)
44
+ with demo:
45
+ gr.Markdown(title)
46
+ gr.Markdown(description)
47
+ gr.Markdown(twitter_link)
48
+
49
+
50
+ with gr.Tabs():
51
+ with gr.TabItem("Upload audio"):
52
+ iface = gr.Interface(
53
+ inference,
54
+ inputs = gr.Audio(source="upload", type="filepath"),
55
+ outputs = gr.Audio(type="file"),
56
+ examples=[["man.wav"], ["woman.wav"]])
57
+ with gr.TabItem("Record your voice"):
58
+ iface = gr.Interface(
59
+ inference,
60
+ inputs = gr.Audio(source="microphone", label="Record yourself reading something out loud", type="filepath"),
61
+ outputs = gr.Audio(type="file"),
62
+ )
63
+
64
+ gr.Markdown("<div><center><img src='https://visitor-badge.glitch.me/badge?page_id=max_skobeev_fullsubnet_plus_public' alt='visitor badge'></center></div>")
65
+
66
+
67
+ demo.launch(enable_queue=True, debug=True, show_error=True)