Update app.py
Browse files
app.py
CHANGED
@@ -9,6 +9,7 @@ from profanity_check import predict, predict_prob
|
|
9 |
from pydub import AudioSegment
|
10 |
from pydub.playback import play
|
11 |
from subprocess import Popen, PIPE
|
|
|
12 |
|
13 |
def parse_args():
|
14 |
"""
|
@@ -212,72 +213,21 @@ def mask_profanities(vocal_stem, profanities):
|
|
212 |
return vocals
|
213 |
|
214 |
|
|
|
|
|
|
|
|
|
|
|
|
|
215 |
if __name__ == "__main__":
|
216 |
args = parse_args()
|
217 |
|
218 |
if len(sys.argv)>1:
|
219 |
main(args, skip_ss=False)
|
220 |
else:
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
This app processes an input audio track (.mp3 or .wav) with the purpose of identifying and muting profanities in the song.
|
226 |
-
|
227 |
-
|
228 |
-
A larger model takes longer to run and is more accurate, and vice-versa.
|
229 |
-
|
230 |
-
|
231 |
-
Simply select the model size and upload your file!
|
232 |
-
''')
|
233 |
-
model = st.selectbox('Choose model size:', ('tiny','small','medium'), index=1)
|
234 |
-
|
235 |
-
uploaded_file = st.file_uploader(
|
236 |
-
"Choose input track:",
|
237 |
-
type=[".mp3",".wav"],
|
238 |
-
accept_multiple_files=False,
|
239 |
)
|
240 |
-
|
241 |
-
if uploaded_file is not None:
|
242 |
-
uploaded_file.name = uploaded_file.name.replace(' ','_')
|
243 |
-
ext = os.path.splitext(uploaded_file.name)[1]
|
244 |
-
if ext == '.wav':
|
245 |
-
st_format = 'audio/wav'
|
246 |
-
elif ext == '.mp3':
|
247 |
-
st_format = 'audio/mp3'
|
248 |
-
|
249 |
-
uploaded_file_content = uploaded_file.getvalue()
|
250 |
-
with open(uploaded_file.name, 'wb') as f:
|
251 |
-
f.write(uploaded_file_content)
|
252 |
-
|
253 |
-
audio_bytes_input = uploaded_file_content
|
254 |
-
st.audio(audio_bytes_input, format=st_format)
|
255 |
-
|
256 |
-
# run code
|
257 |
-
with st.spinner('Processing input audio...'):
|
258 |
-
inpath = os.path.abspath(uploaded_file.name)
|
259 |
-
outpath, vocal_stem, instr_stem = main(args, input_file=inpath, model_size=model)
|
260 |
-
|
261 |
-
if outpath == 'No profanities found':
|
262 |
-
st.text(outpath + ' - Refresh the page and try a different song or model size')
|
263 |
-
sys.exit()
|
264 |
-
|
265 |
-
# display output audio
|
266 |
-
#st.text('Play output Track:')
|
267 |
-
st.text('\nOutput:')
|
268 |
-
audio_file = open(outpath, 'rb')
|
269 |
-
audio_bytes = audio_file.read()
|
270 |
-
st.audio(audio_bytes, format=st_format)
|
271 |
-
|
272 |
-
# flush all media
|
273 |
-
if os.path.isfile(inpath):
|
274 |
-
os.remove(inpath)
|
275 |
-
if os.path.isfile(outpath):
|
276 |
-
os.remove(outpath)
|
277 |
-
if os.path.isfile(vocal_stem):
|
278 |
-
os.remove(vocal_stem)
|
279 |
-
if os.path.isfile(instr_stem):
|
280 |
-
os.remove(instr_stem)
|
281 |
-
sep_dir = os.path.split(instr_stem)[0]
|
282 |
-
if os.path.isdir(sep_dir):
|
283 |
-
os.rmdir(sep_dir)
|
|
|
9 |
from pydub import AudioSegment
|
10 |
from pydub.playback import play
|
11 |
from subprocess import Popen, PIPE
|
12 |
+
import gradio as gr
|
13 |
|
14 |
def parse_args():
|
15 |
"""
|
|
|
213 |
return vocals
|
214 |
|
215 |
|
216 |
+
def process_audio(input_file, model_size):
|
217 |
+
args = parse_args()
|
218 |
+
inpath = os.path.abspath(input_file.name)
|
219 |
+
outpath, vocal_stem, instr_stem = main(args, input_file=inpath, model_size=model_size)
|
220 |
+
return outpath
|
221 |
+
|
222 |
if __name__ == "__main__":
|
223 |
args = parse_args()
|
224 |
|
225 |
if len(sys.argv)>1:
|
226 |
main(args, skip_ss=False)
|
227 |
else:
|
228 |
+
iface = gr.Interface(
|
229 |
+
fn=process_audio,
|
230 |
+
inputs=[gr.inputs.Audio(source="upload"), gr.inputs.Radio(['tiny','small','medium'])],
|
231 |
+
outputs=gr.outputs.Audio(type="file")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
232 |
)
|
233 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|