mariesig commited on
Commit
fe2c42f
·
1 Parent(s): fe08b14

remove option for noise adding

Browse files
Files changed (1) hide show
  1. app.py +1 -31
app.py CHANGED
@@ -1,5 +1,4 @@
1
  import os
2
- from random import sample
3
  import time
4
  from typing import Optional, Any
5
 
@@ -7,9 +6,6 @@ import gradio as gr
7
  from loguru import logger
8
 
9
  from constants import (
10
- NOISES,
11
- SNR_LEVELS,
12
- NOISE_TYPES,
13
  MINUTES_KEEP,
14
  )
15
  from sdk import SDKParams, process_file_sdk
@@ -53,8 +49,6 @@ def cleanup_tmp(minutes_keep: int = MINUTES_KEEP, filter: list[str] = []):
53
 
54
  def denoise_audio(
55
  sample_path: str,
56
- noise_type: str,
57
- snr: str,
58
  enhancement_level: float = 50.0,
59
  ) -> tuple[Optional[str], Optional[str], Optional[str], Optional[str]]:
60
  gr.Info(
@@ -65,17 +59,7 @@ def denoise_audio(
65
  noisy_path = f"{base}_noisy{ext}"
66
  noisy_spec_path = f"{base}_noisy_spectrogram.png"
67
  enhanced_spec_path = f"{base}_enhanced_spectrogram.png"
68
- if noise_type != "None":
69
- clipped = mix_at_snr(
70
- signal_path=sample_path,
71
- noise_path=NOISES[noise_type],
72
- output_path=noisy_path,
73
- snr_db=int(snr),
74
- )
75
- if clipped:
76
- gr.Warning("Adding noise caused clipping. Normalizing might alter the SNR.")
77
- else:
78
- noisy_path = sample_path
79
  try:
80
  sdk_key = os.getenv("SECRET_SDK_KEY")
81
  sdk_params = SDKParams(
@@ -190,17 +174,6 @@ with gr.Blocks() as demo:
190
  audio_file = gr.Audio(
191
  type="filepath", label="Input", visible=True, sources=["upload", "microphone"]
192
  )
193
- noise_type = gr.Dropdown(
194
- label="Add noise",
195
- choices=[*NOISE_TYPES],
196
- value="None",
197
- )
198
- noise_level = gr.Dropdown(
199
- label="Noise Level (SNR)",
200
- choices=[*SNR_LEVELS],
201
- value="None",
202
- visible=False,
203
- )
204
  percent_slider = gr.Slider(
205
  minimum=1,
206
  maximum=100,
@@ -228,13 +201,10 @@ with gr.Blocks() as demo:
228
  denoise_audio,
229
  inputs=[
230
  input_enhancement,
231
- noise_type,
232
- noise_level,
233
  percent_slider,
234
  ],
235
  outputs=[noisy_audio, noisy_image, enhanced_audio, enhanced_image],
236
  ).then(enable_new_input, None, btn)
237
- noise_type.change(toggle_SNR, noise_type, noise_level)
238
 
239
  cleanup_tmp(minutes_keep=0, filter=[])
240
  demo.launch(allowed_paths=["/tmp", "/"])
 
1
  import os
 
2
  import time
3
  from typing import Optional, Any
4
 
 
6
  from loguru import logger
7
 
8
  from constants import (
 
 
 
9
  MINUTES_KEEP,
10
  )
11
  from sdk import SDKParams, process_file_sdk
 
49
 
50
  def denoise_audio(
51
  sample_path: str,
 
 
52
  enhancement_level: float = 50.0,
53
  ) -> tuple[Optional[str], Optional[str], Optional[str], Optional[str]]:
54
  gr.Info(
 
59
  noisy_path = f"{base}_noisy{ext}"
60
  noisy_spec_path = f"{base}_noisy_spectrogram.png"
61
  enhanced_spec_path = f"{base}_enhanced_spectrogram.png"
62
+ noisy_path = sample_path
 
 
 
 
 
 
 
 
 
 
63
  try:
64
  sdk_key = os.getenv("SECRET_SDK_KEY")
65
  sdk_params = SDKParams(
 
174
  audio_file = gr.Audio(
175
  type="filepath", label="Input", visible=True, sources=["upload", "microphone"]
176
  )
 
 
 
 
 
 
 
 
 
 
 
177
  percent_slider = gr.Slider(
178
  minimum=1,
179
  maximum=100,
 
201
  denoise_audio,
202
  inputs=[
203
  input_enhancement,
 
 
204
  percent_slider,
205
  ],
206
  outputs=[noisy_audio, noisy_image, enhanced_audio, enhanced_image],
207
  ).then(enable_new_input, None, btn)
 
208
 
209
  cleanup_tmp(minutes_keep=0, filter=[])
210
  demo.launch(allowed_paths=["/tmp", "/"])