jhtonyKoo commited on
Commit
36d6869
·
1 Parent(s): 8ce0302

modify youtube download

Browse files
Files changed (1) hide show
  1. app.py +38 -11
app.py CHANGED
@@ -47,6 +47,12 @@ def process_youtube_url(url):
47
  except Exception as e:
48
  return None, f"Error processing YouTube URL: {str(e)}"
49
 
 
 
 
 
 
 
50
  def process_audio_with_youtube(input_audio, input_youtube_url, reference_audio, reference_youtube_url):
51
  if input_youtube_url:
52
  input_audio, error = process_youtube_url(input_youtube_url)
@@ -191,6 +197,9 @@ with gr.Blocks() as demo:
191
  with gr.Row():
192
  input_youtube_url = gr.Textbox(label="Input YouTube URL")
193
  reference_youtube_url = gr.Textbox(label="Reference YouTube URL")
 
 
 
194
  with gr.Row():
195
  input_audio_yt = gr.Audio(label="Source Audio (Do not put when using YouTube URL)")
196
  reference_audio_yt = gr.Audio(label="Reference Style Audio (Do not put when using YouTube URL)")
@@ -200,24 +209,42 @@ with gr.Blocks() as demo:
200
 
201
  with gr.Row():
202
  with gr.Column():
203
- output_audio = gr.Audio(label="Output Audio y'", type='numpy')
204
- normalized_input = gr.Audio(label="Normalized Source Audio", type='numpy')
205
- param_output = gr.Textbox(label="Predicted Parameters", lines=5)
206
 
207
  error_message_yt = gr.Textbox(label="Error Message", visible=False)
208
 
209
- def process_and_handle_errors(input_audio, input_youtube_url, reference_audio, reference_youtube_url):
210
- result = process_audio_with_youtube(input_audio, input_youtube_url, reference_audio, reference_youtube_url)
211
- if len(result) == 3 and isinstance(result[2], str): # Error occurred check
212
- return None, None, None, gr.update(visible=True, value=result[2])
213
- return result[0], result[1], result[2], gr.update(visible=False, value="")
 
 
 
 
 
 
214
 
215
  process_button_yt.click(
216
- process_and_handle_errors,
217
- inputs=[input_audio_yt, input_youtube_url, reference_audio_yt, reference_youtube_url],
218
- outputs=[output_audio_yt, param_output_yt, normalized_input, error_message_yt]
219
  )
220
 
 
 
 
 
 
 
 
 
 
 
 
 
221
  gr.Markdown("## Step 2: Inference Time Optimization (ITO)")
222
 
223
  with gr.Row():
 
47
  except Exception as e:
48
  return None, f"Error processing YouTube URL: {str(e)}"
49
 
50
+ def download_youtube_audios(input_youtube_url, reference_youtube_url):
51
+ input_audio, input_error = process_youtube_url(input_youtube_url) if input_youtube_url else (None, None)
52
+ reference_audio, reference_error = process_youtube_url(reference_youtube_url) if reference_youtube_url else (None, None)
53
+
54
+ return input_audio, reference_audio, input_error, reference_error
55
+
56
  def process_audio_with_youtube(input_audio, input_youtube_url, reference_audio, reference_youtube_url):
57
  if input_youtube_url:
58
  input_audio, error = process_youtube_url(input_youtube_url)
 
197
  with gr.Row():
198
  input_youtube_url = gr.Textbox(label="Input YouTube URL")
199
  reference_youtube_url = gr.Textbox(label="Reference YouTube URL")
200
+
201
+ download_button = gr.Button("Download YouTube Audios")
202
+
203
  with gr.Row():
204
  input_audio_yt = gr.Audio(label="Source Audio (Do not put when using YouTube URL)")
205
  reference_audio_yt = gr.Audio(label="Reference Style Audio (Do not put when using YouTube URL)")
 
209
 
210
  with gr.Row():
211
  with gr.Column():
212
+ output_audio_yt = gr.Audio(label="Output Audio y'", type='numpy')
213
+ normalized_input_yt = gr.Audio(label="Normalized Source Audio", type='numpy')
214
+ param_output_yt = gr.Textbox(label="Predicted Parameters", lines=5)
215
 
216
  error_message_yt = gr.Textbox(label="Error Message", visible=False)
217
 
218
+ def handle_download_youtube_audios(input_youtube_url, reference_youtube_url):
219
+ input_audio, reference_audio, input_error, reference_error = download_youtube_audios(input_youtube_url, reference_youtube_url)
220
+ if input_error or reference_error:
221
+ return None, None, gr.update(visible=True, value=input_error or reference_error)
222
+ return input_audio, reference_audio, gr.update(visible=False, value="")
223
+
224
+ download_button.click(
225
+ handle_download_youtube_audios,
226
+ inputs=[input_youtube_url, reference_youtube_url],
227
+ outputs=[input_audio_yt, reference_audio_yt, error_message_yt]
228
+ )
229
 
230
  process_button_yt.click(
231
+ process_audio,
232
+ inputs=[input_audio_yt, reference_audio_yt],
233
+ outputs=[output_audio_yt, param_output_yt, normalized_input_yt]
234
  )
235
 
236
+ # def process_and_handle_errors(input_audio, input_youtube_url, reference_audio, reference_youtube_url):
237
+ # result = process_audio_with_youtube(input_audio, input_youtube_url, reference_audio, reference_youtube_url)
238
+ # if len(result) == 3 and isinstance(result[2], str): # Error occurred check
239
+ # return None, None, None, gr.update(visible=True, value=result[2])
240
+ # return result[0], result[1], result[2], gr.update(visible=False, value="")
241
+
242
+ # process_button_yt.click(
243
+ # process_and_handle_errors,
244
+ # inputs=[input_audio_yt, input_youtube_url, reference_audio_yt, reference_youtube_url],
245
+ # outputs=[output_audio_yt, param_output_yt, normalized_input_yt, error_message_yt]
246
+ # )
247
+
248
  gr.Markdown("## Step 2: Inference Time Optimization (ITO)")
249
 
250
  with gr.Row():