Dhruv73 commited on
Commit
e02f1d6
1 Parent(s): f5063ae

Add application file

Browse files
app.py ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # Importing libraries
3
+
4
+ import gradio as gr
5
+ from asteroid.models import ConvTasNet, DPRNNTasNet
6
+ import torch
7
+ import os
8
+ import shutil
9
+
10
+
11
+ # ------------------ #
12
+
13
+ class tester():
14
+ def __init__(self, model):
15
+ # Modeling
16
+ self.model = model
17
+ # Test Directory will also contain output after files
18
+ self.test_dir = '/asset/test_subject/'
19
+ def prepare_test(self):
20
+ # Removing older test and their results
21
+ if os.path.exists(self.test_dir):
22
+ shutil.rmtree(self.test_dir)
23
+
24
+ if not os.path.exists(self.test_dir):
25
+ os.mkdir(self.test_dir)
26
+ def test(self, path):
27
+ self.prepare_test()
28
+
29
+ test_subject = self.test_dir + 'test.wav'
30
+ shutil.copyfile(path, test_subject)
31
+
32
+ self.model.separate(test_subject,force_overwrite=True, resample=True)
33
+
34
+ def load_model():
35
+ model = torch.load('/asset/model/model_two.bin')
36
+ return model
37
+
38
+ def separator(original_audio, path):
39
+ Test = tester(load_model())
40
+ Test.prepare_test()
41
+ Test.test(path)
42
+
43
+ separated_audios = list()
44
+ separated_audios.append('/asset/test_subject/test.wav')
45
+ separated_audios.append('/asset/test_subject/test_est1.wav')
46
+ separated_audios.append('/asset/test_subject/test_est2.wav')
47
+
48
+ return separated_audios
49
+
50
+ demo = gr.Blocks(theme=gr.themes.Soft())
51
+ with demo:
52
+
53
+ gr.Markdown('''
54
+ <center>
55
+ <h1>Speech Separation</h1>
56
+ <div style="display:flex;align-items:center;justify-content:center;">
57
+ <iframe src="https://streamable.com/e/uribry?autoplay=1&nocontrols=1" frameborder="0" allow="autoplay">
58
+ </iframe>
59
+ </div>
60
+ <div></div>
61
+ <p>
62
+ It is a shareable demonstration window which can be used to view result on any device by setting 'share' a launch parameter 'True'.
63
+ It displays original audio for mixture of speaker, seperated audio by our model and original individual speaker audio.
64
+ </p>
65
+ </center>
66
+ ''')
67
+
68
+ with gr.Row():
69
+ pass
70
+ with gr.Row():
71
+ pass
72
+ gr.Markdown('''
73
+ <h2> Original Audio</h2>
74
+
75
+ ''')
76
+ with gr.Row():
77
+ output_text1 = gr.Text("Original Speech signal ", label='Original Audio', interactive=False)
78
+ original_audio = gr.Audio(label='Original Audio', interactive=False)
79
+
80
+ with gr.Row():
81
+ pass
82
+ with gr.Row():
83
+ pass
84
+ gr.Markdown('''
85
+ <h2> Separated Audio</h2>
86
+
87
+ ''')
88
+
89
+ with gr.Row():
90
+ output_text1 = gr.Text("Separated Speech signal Speaker 1 ", label='Speaker 1', interactive=False)
91
+ output_audio1 = gr.Audio(label='Speaker 1', interactive=False)
92
+ with gr.Row():
93
+ output_text2 = gr.Text("Separated Speech signal Speaker 2 ", label='Speaker 2', interactive=False)
94
+ output_audio2 = gr.Audio(label='Speaker 2', interactive=False)
95
+
96
+
97
+ outputs_audio = [original_audio, output_audio1, output_audio2]
98
+ button = gr.Button("Separate")
99
+ examples = [
100
+ "/asset/test/mix_clean/Audio0.wav",
101
+ "/asset/test/mix_clean/Audio1.wav",
102
+ "/asset/test/mix_clean/Audio2.wav",
103
+ "/asset/test/mix_clean/Audio3.wav"
104
+ ]
105
+
106
+ example_selector = gr.inputs.Radio(examples, label="Example Audio")
107
+ button.click(separator, inputs=[original_audio, example_selector], outputs=outputs_audio)
108
+
109
+ gr.Markdown('''
110
+ <center>
111
+ <div style="display:flex;align-items:center;justify-content:center;">
112
+ <a href="https://www.linkedin.com/in/dhruv73/" target="blank">
113
+ <img src="https://raw.githubusercontent.com/devicons/devicon/1119b9f84c0290e0f0b38982099a2bd027a48bf1/icons/linkedin/linkedin-original.svg" alt="LinkedIN: /dhruv_73" width="100" height="100"/>
114
+ </a>
115
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
116
+ <a href="https://github.com/DS-73" target="_blank">
117
+ <img src="https://raw.githubusercontent.com/devicons/devicon/1119b9f84c0290e0f0b38982099a2bd027a48bf1/icons/github/github-original.svg" alt="Github: /DS-73" width="100" height="100"/>
118
+ </a>
119
+ </div>
120
+ </center>
121
+ ''')
122
+
123
+ demo.launch()
124
+
125
+
126
+
127
+ # ------------------ #
asset/model/model_two.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1a6b78dc3ba01e592970d9ce9cda9a1ce0ac003d000aad93ae6833e254a36612
3
+ size 20410329
asset/test/mix_clean/Audio0.wav ADDED
Binary file (88.4 kB). View file
 
asset/test/mix_clean/Audio1.wav ADDED
Binary file (139 kB). View file
 
asset/test/mix_clean/Audio2.wav ADDED
Binary file (225 kB). View file
 
asset/test/mix_clean/Audio3.wav ADDED
Binary file (194 kB). View file
 
asset/test/s1/Audio0.wav ADDED
Binary file (88.4 kB). View file
 
asset/test/s1/Audio1.wav ADDED
Binary file (139 kB). View file
 
asset/test/s1/Audio2.wav ADDED
Binary file (225 kB). View file
 
asset/test/s1/Audio3.wav ADDED
Binary file (194 kB). View file
 
asset/test/s2/Audio0.wav ADDED
Binary file (88.4 kB). View file
 
asset/test/s2/Audio1.wav ADDED
Binary file (139 kB). View file
 
asset/test/s2/Audio2.wav ADDED
Binary file (225 kB). View file
 
asset/test/s2/Audio3.wav ADDED
Binary file (194 kB). View file
 
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ gradio==3.34.0
2
+ gradio_client==0.2.6
3
+ torch==2.0.1
4
+ asteroid==0.6.0
5
+ asteroid-filterbanks==0.4.0
6
+ os
7
+ shutil