juancopi81 commited on
Commit
7a8f502
1 Parent(s): c2a3f2d

Use gradio 3.11 and remove time constrain

Browse files
Files changed (2) hide show
  1. README.md +1 -1
  2. app.py +6 -16
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: 🐨
4
  colorFrom: blue
5
  colorTo: red
6
  sdk: gradio
7
- sdk_version: 3.8.2
8
  python_version: 3.7
9
  app_file: app.py
10
  pinned: false
 
4
  colorFrom: blue
5
  colorTo: red
6
  sdk: gradio
7
+ sdk_version: 3.11.0
8
  python_version: 3.7
9
  app_file: app.py
10
  pinned: false
app.py CHANGED
@@ -40,7 +40,7 @@ def change_model(model):
40
  current_model = model
41
 
42
  # Credits https://huggingface.co/spaces/rajesh1729/youtube-video-transcription-with-whisper
43
- def get_audio(url, start_second):
44
  yt = YouTube(url)
45
  video = yt.streams.filter(only_audio=True).first()
46
  out_file = video.download(output_path=".")
@@ -48,19 +48,12 @@ def get_audio(url, start_second):
48
  new_file = base + ".wav"
49
  os.rename(out_file, new_file)
50
  a = new_file
51
- wav_to_cut = AudioSegment.from_file(a)
52
- # pydub does things in milliseconds
53
- ten_seconds = 10 * 1000
54
- start_second = start_second * 1000
55
- first_10_seconds = wav_to_cut[start_second:start_second+ten_seconds]
56
- os.remove(new_file)
57
- first_10_seconds.export("final_audio.wav", format="wav")
58
- return "final_audio.wav"
59
 
60
  # Credits https://huggingface.co/spaces/jeffistyping/Youtube-Whisperer
61
- def populate_metadata(link, start_second):
62
  yt = YouTube(link)
63
- audio = get_audio(link, start_second)
64
  return yt.thumbnail_url, yt.title, audio, audio
65
 
66
  def inference(yt_audio_path):
@@ -95,7 +88,7 @@ demo = gr.Blocks()
95
 
96
  # Use your Block object as a context
97
  with demo:
98
- gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'>"
99
  + title
100
  + "</h1>")
101
  gr.Markdown(description)
@@ -114,9 +107,6 @@ with demo:
114
 
115
  with gr.Row():
116
  link = gr.Textbox(label="YouTube Link")
117
- start_second = gr.Number(label="Select starting point (in seconds) for the transcription",
118
- value=0,
119
- precision=0)
120
  with gr.Row():
121
  preview_btn = gr.Button("Preview")
122
  with gr.Row().style(mobile_collapse=False, equal_height=True):
@@ -127,7 +117,7 @@ with demo:
127
  yt_audio_path = gr.Textbox(visible=False)
128
 
129
  preview_btn.click(fn=populate_metadata,
130
- inputs=[link, start_second],
131
  outputs=[img, title, yt_audio, yt_audio_path])
132
 
133
  with gr.Row():
 
40
  current_model = model
41
 
42
  # Credits https://huggingface.co/spaces/rajesh1729/youtube-video-transcription-with-whisper
43
+ def get_audio(url):
44
  yt = YouTube(url)
45
  video = yt.streams.filter(only_audio=True).first()
46
  out_file = video.download(output_path=".")
 
48
  new_file = base + ".wav"
49
  os.rename(out_file, new_file)
50
  a = new_file
51
+ return a
 
 
 
 
 
 
 
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):
 
88
 
89
  # Use your Block object as a context
90
  with demo:
91
+ gr.Markdown("<h1 style='text-align: center'>"
92
  + title
93
  + "</h1>")
94
  gr.Markdown(description)
 
107
 
108
  with gr.Row():
109
  link = gr.Textbox(label="YouTube Link")
 
 
 
110
  with gr.Row():
111
  preview_btn = gr.Button("Preview")
112
  with gr.Row().style(mobile_collapse=False, equal_height=True):
 
117
  yt_audio_path = gr.Textbox(visible=False)
118
 
119
  preview_btn.click(fn=populate_metadata,
120
+ inputs=[link],
121
  outputs=[img, title, yt_audio, yt_audio_path])
122
 
123
  with gr.Row():