Spaces:
Running
Running
refactor: simplify audio input by consolidating microphone and file uploads into a single Gradio Audio component
Browse files- app.py +6 -26
- requirements.txt +1 -1
app.py
CHANGED
|
@@ -169,10 +169,7 @@ def demo_fn(
|
|
| 169 |
atten_lim_db: float,
|
| 170 |
wet_dry_mix: float,
|
| 171 |
post_process: bool,
|
| 172 |
-
mic_input: Optional[str] = None,
|
| 173 |
):
|
| 174 |
-
if mic_input:
|
| 175 |
-
speech_upl = mic_input
|
| 176 |
|
| 177 |
sr = config("sr", 48000, int, section="df")
|
| 178 |
logger.info(f"Got parameters speech_upl: {speech_upl}, noise: {noise_type}, snr: {snr}, atten_lim_db: {atten_lim_db}, wet_dry_mix: {wet_dry_mix}, post_process: {post_process}")
|
|
@@ -251,8 +248,6 @@ def demo_fn(
|
|
| 251 |
enh_im = spec_im(enhanced, sr=sr, figure=fig_enh, ax=ax_enh)
|
| 252 |
|
| 253 |
filter = [speech_upl, noisy_mp3, enhanced_mp3]
|
| 254 |
-
if mic_input is not None and mic_input != "":
|
| 255 |
-
filter.append(mic_input)
|
| 256 |
cleanup_tmp(filter)
|
| 257 |
|
| 258 |
return noisy_mp3, noisy_im, enhanced_mp3, enh_im
|
|
@@ -369,15 +364,6 @@ def cleanup_tmp(filter: List[str] = [], hours_keep=2):
|
|
| 369 |
logger.info(f"Removed file {f}")
|
| 370 |
except Exception as e:
|
| 371 |
logger.warning(f"failed to remove file {f}: {e}")
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
def toggle(choice):
|
| 375 |
-
if choice == "mic":
|
| 376 |
-
return gr.update(visible=True, value=None), gr.update(visible=False, value=None)
|
| 377 |
-
else:
|
| 378 |
-
return gr.update(visible=False, value=None), gr.update(visible=True, value=None)
|
| 379 |
-
|
| 380 |
-
|
| 381 |
with gr.Blocks() as demo:
|
| 382 |
with gr.Row():
|
| 383 |
gr.Markdown(
|
|
@@ -389,11 +375,7 @@ with gr.Blocks() as demo:
|
|
| 389 |
)
|
| 390 |
with gr.Row():
|
| 391 |
with gr.Column():
|
| 392 |
-
|
| 393 |
-
["mic", "file"], value="file", label="How would you like to upload your audio?"
|
| 394 |
-
)
|
| 395 |
-
mic_input = gr.Mic(label="Input", type="filepath", visible=False)
|
| 396 |
-
audio_file = gr.Audio(type="filepath", label="Input", visible=True)
|
| 397 |
inputs = [
|
| 398 |
audio_file,
|
| 399 |
gr.Dropdown(
|
|
@@ -424,7 +406,6 @@ with gr.Blocks() as demo:
|
|
| 424 |
label="Post-Process (80Hz Low-Cut & Presence Boost)",
|
| 425 |
value=True,
|
| 426 |
),
|
| 427 |
-
mic_input,
|
| 428 |
]
|
| 429 |
btn = gr.Button("Generate")
|
| 430 |
with gr.Column():
|
|
@@ -437,19 +418,18 @@ with gr.Blocks() as demo:
|
|
| 437 |
gr.Image(label="Enhanced spectrogram"),
|
| 438 |
]
|
| 439 |
btn.click(fn=demo_fn, inputs=inputs, outputs=outputs, api_name='denoise')
|
| 440 |
-
radio.change(toggle, radio, [mic_input, audio_file])
|
| 441 |
gr.Examples(
|
| 442 |
[
|
| 443 |
-
["./samples/p232_013_clean.wav", "Kitchen", "10", 15, 90, True
|
| 444 |
-
["./samples/p232_013_clean.wav", "Cafe", "10", 15, 90, True
|
| 445 |
-
["./samples/p232_019_clean.wav", "Cafe", "10", 15, 90, True
|
| 446 |
-
["./samples/p232_019_clean.wav", "River", "10", 15, 90, True
|
| 447 |
],
|
| 448 |
fn=demo_fn,
|
| 449 |
inputs=inputs,
|
| 450 |
outputs=outputs,
|
| 451 |
cache_examples=True,
|
| 452 |
-
)
|
| 453 |
gr.Markdown(open("usage.md").read())
|
| 454 |
|
| 455 |
cleanup_tmp()
|
|
|
|
| 169 |
atten_lim_db: float,
|
| 170 |
wet_dry_mix: float,
|
| 171 |
post_process: bool,
|
|
|
|
| 172 |
):
|
|
|
|
|
|
|
| 173 |
|
| 174 |
sr = config("sr", 48000, int, section="df")
|
| 175 |
logger.info(f"Got parameters speech_upl: {speech_upl}, noise: {noise_type}, snr: {snr}, atten_lim_db: {atten_lim_db}, wet_dry_mix: {wet_dry_mix}, post_process: {post_process}")
|
|
|
|
| 248 |
enh_im = spec_im(enhanced, sr=sr, figure=fig_enh, ax=ax_enh)
|
| 249 |
|
| 250 |
filter = [speech_upl, noisy_mp3, enhanced_mp3]
|
|
|
|
|
|
|
| 251 |
cleanup_tmp(filter)
|
| 252 |
|
| 253 |
return noisy_mp3, noisy_im, enhanced_mp3, enh_im
|
|
|
|
| 364 |
logger.info(f"Removed file {f}")
|
| 365 |
except Exception as e:
|
| 366 |
logger.warning(f"failed to remove file {f}: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 367 |
with gr.Blocks() as demo:
|
| 368 |
with gr.Row():
|
| 369 |
gr.Markdown(
|
|
|
|
| 375 |
)
|
| 376 |
with gr.Row():
|
| 377 |
with gr.Column():
|
| 378 |
+
audio_file = gr.Audio(sources=["upload", "microphone"], type="filepath", label="Input Audio")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 379 |
inputs = [
|
| 380 |
audio_file,
|
| 381 |
gr.Dropdown(
|
|
|
|
| 406 |
label="Post-Process (80Hz Low-Cut & Presence Boost)",
|
| 407 |
value=True,
|
| 408 |
),
|
|
|
|
| 409 |
]
|
| 410 |
btn = gr.Button("Generate")
|
| 411 |
with gr.Column():
|
|
|
|
| 418 |
gr.Image(label="Enhanced spectrogram"),
|
| 419 |
]
|
| 420 |
btn.click(fn=demo_fn, inputs=inputs, outputs=outputs, api_name='denoise')
|
|
|
|
| 421 |
gr.Examples(
|
| 422 |
[
|
| 423 |
+
["./samples/p232_013_clean.wav", "Kitchen", "10", 15, 90, True],
|
| 424 |
+
["./samples/p232_013_clean.wav", "Cafe", "10", 15, 90, True],
|
| 425 |
+
["./samples/p232_019_clean.wav", "Cafe", "10", 15, 90, True],
|
| 426 |
+
["./samples/p232_019_clean.wav", "River", "10", 15, 90, True],
|
| 427 |
],
|
| 428 |
fn=demo_fn,
|
| 429 |
inputs=inputs,
|
| 430 |
outputs=outputs,
|
| 431 |
cache_examples=True,
|
| 432 |
+
)
|
| 433 |
gr.Markdown(open("usage.md").read())
|
| 434 |
|
| 435 |
cleanup_tmp()
|
requirements.txt
CHANGED
|
@@ -2,5 +2,5 @@ torch==1.13
|
|
| 2 |
torchaudio==0.13
|
| 3 |
deepfilternet==0.4.0
|
| 4 |
matplotlib==3.6
|
| 5 |
-
|
| 6 |
Pillow==9.3
|
|
|
|
| 2 |
torchaudio==0.13
|
| 3 |
deepfilternet==0.4.0
|
| 4 |
matplotlib==3.6
|
| 5 |
+
gradio==5.48.0
|
| 6 |
Pillow==9.3
|