jhtonyKoo commited on
Commit
ad763a0
1 Parent(s): 8c11be7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -6
app.py CHANGED
@@ -25,11 +25,11 @@ yt_video_dir = "./yt_dir"
25
  os.makedirs(yt_video_dir, exist_ok=True)
26
 
27
 
28
- def get_audio_from_yt_video(yt_link: str, tag: str):
29
  try:
30
  yt = pt.YouTube(yt_link)
31
  t = yt.streams.filter(only_audio=True)
32
- filename = os.path.join(yt_video_dir, tag + ".wav")
33
  t[0].download(filename=filename)
34
  except VideoUnavailable as e:
35
  warnings.warn(f"Video Not Found at {yt_link} ({e})")
@@ -37,6 +37,17 @@ def get_audio_from_yt_video(yt_link: str, tag: str):
37
 
38
  return filename, filename
39
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
  def inference(file_uploaded_in, file_uploaded_ref):
42
 
@@ -88,8 +99,8 @@ with gr.Blocks() as demo:
88
  label="Input Audio Extracted from the YouTube Video", interactive=False
89
  )
90
  yt_btn_in.click(
91
- get_audio_from_yt_video,
92
- inputs=[yt_link_in, 'input'],
93
  outputs=[yt_audio_path_in, file_uploaded_in],
94
  )
95
  with gr.Blocks():
@@ -105,8 +116,8 @@ with gr.Blocks() as demo:
105
  label="Reference Audio Extracted from the YouTube Video", interactive=False
106
  )
107
  yt_btn_ref.click(
108
- get_audio_from_yt_video,
109
- inputs=[yt_link_ref, 'reference'],
110
  outputs=[yt_audio_path_ref, file_uploaded_ref],
111
  )
112
  with gr.Column():
 
25
  os.makedirs(yt_video_dir, exist_ok=True)
26
 
27
 
28
+ def get_audio_from_yt_video_input(yt_link: str)
29
  try:
30
  yt = pt.YouTube(yt_link)
31
  t = yt.streams.filter(only_audio=True)
32
+ filename = os.path.join(yt_video_dir, "input.wav")
33
  t[0].download(filename=filename)
34
  except VideoUnavailable as e:
35
  warnings.warn(f"Video Not Found at {yt_link} ({e})")
 
37
 
38
  return filename, filename
39
 
40
+ def get_audio_from_yt_video_ref(yt_link: str)
41
+ try:
42
+ yt = pt.YouTube(yt_link)
43
+ t = yt.streams.filter(only_audio=True)
44
+ filename = os.path.join(yt_video_dir, "reference.wav")
45
+ t[0].download(filename=filename)
46
+ except VideoUnavailable as e:
47
+ warnings.warn(f"Video Not Found at {yt_link} ({e})")
48
+ filename = None
49
+
50
+ return filename, filename
51
 
52
  def inference(file_uploaded_in, file_uploaded_ref):
53
 
 
99
  label="Input Audio Extracted from the YouTube Video", interactive=False
100
  )
101
  yt_btn_in.click(
102
+ get_audio_from_yt_video_input,
103
+ inputs=[yt_link_in],
104
  outputs=[yt_audio_path_in, file_uploaded_in],
105
  )
106
  with gr.Blocks():
 
116
  label="Reference Audio Extracted from the YouTube Video", interactive=False
117
  )
118
  yt_btn_ref.click(
119
+ get_audio_from_yt_video_ref,
120
+ inputs=[yt_link_ref],
121
  outputs=[yt_audio_path_ref, file_uploaded_ref],
122
  )
123
  with gr.Column():