juancopi81 commited on
Commit
725e39d
1 Parent(s): ad56fd1

Let users select start second for the transcription

Browse files
Files changed (1) hide show
  1. app.py +12 -6
app.py CHANGED
@@ -34,7 +34,7 @@ def change_model(model):
34
  current_model = model
35
 
36
  # Credits https://huggingface.co/spaces/rajesh1729/youtube-video-transcription-with-whisper
37
- def get_audio(url):
38
  yt = YouTube(url)
39
  video = yt.streams.filter(only_audio=True).first()
40
  out_file = video.download(output_path=".")
@@ -45,15 +45,15 @@ def get_audio(url):
45
  wav_to_cut = AudioSegment.from_file(a)
46
  # pydub does things in milliseconds
47
  ten_seconds = 10 * 1000
48
- first_10_seconds = wav_to_cut[:ten_seconds]
49
  os.remove(new_file)
50
  first_10_seconds.export("final_audio.wav", format="wav")
51
  return "final_audio.wav"
52
 
53
  # Credits https://huggingface.co/spaces/jeffistyping/Youtube-Whisperer
54
- def populate_metadata(link):
55
  yt = YouTube(link)
56
- audio = get_audio(link)
57
  return yt.thumbnail_url, yt.title, audio, audio
58
 
59
  def inference(yt_audio_path):
@@ -105,7 +105,11 @@ with demo:
105
  )
106
  model.change(fn=change_model, inputs=model, outputs=[])
107
 
108
- link = gr.Textbox(label="YouTube Link")
 
 
 
 
109
  with gr.Row().style(mobile_collapse=False, equal_height=True):
110
  title = gr.Label(label="Video Title", placeholder="Title")
111
  img = gr.Image(label="Thumbnail")
@@ -113,7 +117,9 @@ with demo:
113
  yt_audio = gr.Audio()
114
  yt_audio_path = gr.Textbox(visible=False)
115
 
116
- link.change(fn=populate_metadata, inputs=link, outputs=[img, title, yt_audio, yt_audio_path])
 
 
117
 
118
  with gr.Row():
119
  btn = gr.Button("Transcribe music")
 
34
  current_model = model
35
 
36
  # Credits https://huggingface.co/spaces/rajesh1729/youtube-video-transcription-with-whisper
37
+ def get_audio(url, start):
38
  yt = YouTube(url)
39
  video = yt.streams.filter(only_audio=True).first()
40
  out_file = video.download(output_path=".")
 
45
  wav_to_cut = AudioSegment.from_file(a)
46
  # pydub does things in milliseconds
47
  ten_seconds = 10 * 1000
48
+ first_10_seconds = wav_to_cut[start:start+ten_seconds]
49
  os.remove(new_file)
50
  first_10_seconds.export("final_audio.wav", format="wav")
51
  return "final_audio.wav"
52
 
53
  # Credits https://huggingface.co/spaces/jeffistyping/Youtube-Whisperer
54
+ def populate_metadata(link, start_second):
55
  yt = YouTube(link)
56
+ audio = get_audio(link, start_second)
57
  return yt.thumbnail_url, yt.title, audio, audio
58
 
59
  def inference(yt_audio_path):
 
105
  )
106
  model.change(fn=change_model, inputs=model, outputs=[])
107
 
108
+ with gr.Row():
109
+ link = gr.Textbox(label="YouTube Link")
110
+ start_second = gr.Number(label="Select starting point (in seconds) for the transcription",
111
+ value=0,
112
+ precision=0)
113
  with gr.Row().style(mobile_collapse=False, equal_height=True):
114
  title = gr.Label(label="Video Title", placeholder="Title")
115
  img = gr.Image(label="Thumbnail")
 
117
  yt_audio = gr.Audio()
118
  yt_audio_path = gr.Textbox(visible=False)
119
 
120
+ link.change(fn=populate_metadata,
121
+ inputs=[link, start_second],
122
+ outputs=[img, title, yt_audio, yt_audio_path])
123
 
124
  with gr.Row():
125
  btn = gr.Button("Transcribe music")