jhtonyKoo commited on
Commit
e32542e
1 Parent(s): e43ae33

add examples

Browse files
Files changed (1) hide show
  1. app.py +24 -12
app.py CHANGED
@@ -173,22 +173,26 @@ with gr.Blocks() as demo:
173
  gr.Markdown("Interactive demo of Inference Time Optimization (ITO) for Music Mastering Style Transfer. \
174
  The mastering style transfer is performed by a differentiable audio processing model, and the predicted parameters are shown as the output. \
175
  Perform mastering style transfer with an input source audio and a reference mastering style audio. On top of this result, you can perform ITO to optimize the reference embedding $z_{ref}$ to further gain control over the output mastering style.")
176
- gr.Image("ito_snow.png", width=100, label="ITO pipeline")
177
 
178
  gr.Markdown("## Step 1: Mastering Style Transfer")
179
 
180
  with gr.Tab("Upload Audio"):
181
  with gr.Row():
182
- input_audio = gr.Audio(label="Source Audio $x_{in}$")
183
- reference_audio = gr.Audio(label="Reference Style Audio $x_{ref}$")
184
-
 
 
 
185
  # Dropdowns for selecting example files
186
  with gr.Row():
187
- input_example_dropdown = gr.Dropdown(label="Select Input Example", choices=input_examples)
188
- reference_example_dropdown = gr.Dropdown(label="Select Reference Example", choices=reference_examples)
189
 
190
  process_button = gr.Button("Process Mastering Style Transfer")
191
  gr.Markdown('<span style="color: lightgray; font-style: italic;">all output samples are normalized to -12dB</span>')
 
192
 
193
  with gr.Row():
194
  with gr.Column():
@@ -196,19 +200,27 @@ with gr.Blocks() as demo:
196
  normalized_input = gr.Audio(label="Normalized Source Audio", type='numpy')
197
  param_output = gr.Textbox(label="Predicted Parameters", lines=5)
198
 
199
- def process_audio_with_examples(input_audio, reference_audio, input_example, reference_example):
200
- if input_example:
201
- input_audio = sf.read(os.path.join(EXAMPLES_DIR, input_example))[0]
202
- if reference_example:
203
- reference_audio = sf.read(os.path.join(EXAMPLES_DIR, reference_example))[0]
 
204
  return process_audio(input_audio, reference_audio)
205
 
206
  process_button.click(
207
  process_audio_with_examples,
208
- inputs=[input_audio, reference_audio, input_example_dropdown, reference_example_dropdown],
209
  outputs=[output_audio, param_output, normalized_input]
210
  )
211
 
 
 
 
 
 
 
 
212
  with gr.Tab("YouTube Audio"):
213
  with gr.Row():
214
  input_youtube_url = gr.Textbox(label="Input YouTube URL")
 
173
  gr.Markdown("Interactive demo of Inference Time Optimization (ITO) for Music Mastering Style Transfer. \
174
  The mastering style transfer is performed by a differentiable audio processing model, and the predicted parameters are shown as the output. \
175
  Perform mastering style transfer with an input source audio and a reference mastering style audio. On top of this result, you can perform ITO to optimize the reference embedding $z_{ref}$ to further gain control over the output mastering style.")
176
+ gr.Image("ito_snow.png", width=300, height=200, label="ITO pipeline")
177
 
178
  gr.Markdown("## Step 1: Mastering Style Transfer")
179
 
180
  with gr.Tab("Upload Audio"):
181
  with gr.Row():
182
+ use_example_files = gr.Checkbox(label="Use Example Files", value=False)
183
+
184
+ with gr.Row():
185
+ input_audio = gr.Audio(label="Source Audio $x_{in}$", interactive=not use_example_files.value)
186
+ reference_audio = gr.Audio(label="Reference Style Audio $x_{ref}$", interactive=not use_example_files.value)
187
+
188
  # Dropdowns for selecting example files
189
  with gr.Row():
190
+ input_example_dropdown = gr.Dropdown(label="Select Input Example", choices=input_examples, interactive=use_example_files.value)
191
+ reference_example_dropdown = gr.Dropdown(label="Select Reference Example", choices=reference_examples, interactive=use_example_files.value)
192
 
193
  process_button = gr.Button("Process Mastering Style Transfer")
194
  gr.Markdown('<span style="color: lightgray; font-style: italic;">all output samples are normalized to -12dB</span>')
195
+ gr.Markdown("all output samples are normalized to -12dB")
196
 
197
  with gr.Row():
198
  with gr.Column():
 
200
  normalized_input = gr.Audio(label="Normalized Source Audio", type='numpy')
201
  param_output = gr.Textbox(label="Predicted Parameters", lines=5)
202
 
203
+ def process_audio_with_examples(input_audio, reference_audio, input_example, reference_example, use_examples):
204
+ if use_examples:
205
+ if input_example:
206
+ input_audio = sf.read(os.path.join(EXAMPLES_DIR, input_example))[0]
207
+ if reference_example:
208
+ reference_audio = sf.read(os.path.join(EXAMPLES_DIR, reference_example))[0]
209
  return process_audio(input_audio, reference_audio)
210
 
211
  process_button.click(
212
  process_audio_with_examples,
213
+ inputs=[input_audio, reference_audio, input_example_dropdown, reference_example_dropdown, use_example_files],
214
  outputs=[output_audio, param_output, normalized_input]
215
  )
216
 
217
+ # Update the interactivity of the audio inputs and dropdowns based on the checkbox
218
+ use_example_files.change(
219
+ lambda use_examples: (not use_examples, not use_examples),
220
+ inputs=[use_example_files],
221
+ outputs=[input_audio, reference_audio]
222
+ )
223
+
224
  with gr.Tab("YouTube Audio"):
225
  with gr.Row():
226
  input_youtube_url = gr.Textbox(label="Input YouTube URL")