saad177 commited on
Commit
0c0335c
1 Parent(s): d7d5bfb

changes in ui

Browse files
Files changed (2) hide show
  1. app.py +45 -48
  2. requirements.txt +2 -1
app.py CHANGED
@@ -1,58 +1,47 @@
1
  from transformers import pipeline
2
  import gradio as gr
3
- from youtube_dl import YoutubeDL
4
 
5
 
6
- # Function to download audio from YouTube link
7
- # def download_audio(youtube_link, output_path):
8
- # ydl_opts = {
9
- # "format": "bestaudio/best",
10
- # "outtmpl": output_path,
11
- # "postprocessors": [
12
- # {
13
- # "key": "FFmpegExtractAudio",
14
- # "preferredcodec": "mp3",
15
- # "preferredquality": "192",
16
- # }
17
- # ],
18
- # }
19
- # with YoutubeDL(ydl_opts) as ydl:
20
- # ydl.download([youtube_link])
21
 
22
 
23
- # def update_visibility(interface, input_type):
24
- # if input_type == "audio":
25
- # interface.set_visibility("audio_input", True)
26
- # interface.set_visibility("youtube_input", False)
27
- # elif input_type == "youtube":
28
- # interface.set_visibility("audio_input", False)
29
- # interface.set_visibility("youtube_input", True)
30
- def transcribe_audio(input_type, audio_path):
31
- if input_type == "Audio":
32
- model = pipeline(model="SofiaK/checkpoints")
33
- return model(audio_path)["text"]
34
 
35
 
36
  with gr.Blocks() as demo:
37
- radio = gr.Radio(
38
- choices=["Audio", "Youtube"], label="Choose your input type", value="Audio"
39
- )
40
- audio_input = gr.Audio(
41
- sources=["upload", "microphone"],
42
- type="filepath",
43
- label="Upload Audio, or speak in the microphone",
44
- visible=True,
45
- interactive=True,
46
- )
47
- youtube_input = gr.Textbox(
48
- value="https://www.youtube.com/",
49
- label="Youtube Link",
50
- visible=False,
51
- interactive=True,
52
- )
53
- btn = gr.Button(
54
- "Transcript",
55
- )
 
 
 
 
 
 
56
 
57
  def make_visible(val):
58
  audio_visible = val == "Audio"
@@ -63,7 +52,15 @@ with gr.Blocks() as demo:
63
 
64
  radio.change(make_visible, inputs=radio, outputs=[audio_input, youtube_input])
65
 
66
- output = gr.Text(label="Model output")
67
- btn.click(fn=transcribe_audio, inputs=[radio, audio_input], outputs=output)
 
 
 
 
 
 
 
 
68
 
69
  demo.launch()
 
1
  from transformers import pipeline
2
  import gradio as gr
3
+ from pytube import YouTube
4
 
5
 
6
+ def dl_youtube_audio(youtube_link):
7
+ yt = YouTube(youtube_link)
8
+ audio_stream = yt.streams.filter(only_audio=True).first()
9
+ audio_path = f"youtube_audio_{yt.video_id}.mp3"
10
+ audio_stream.download(output_path=".", filename="youtube_audio")
11
+ return audio_path
 
 
 
 
 
 
 
 
 
12
 
13
 
14
+ def transcribe_audio(audio_path):
15
+ model = pipeline(model="SofiaK/checkpoints")
16
+ return model(audio_path)["text"]
 
 
 
 
 
 
 
 
17
 
18
 
19
  with gr.Blocks() as demo:
20
+ with gr.Row():
21
+ with gr.Column():
22
+ radio = gr.Radio(
23
+ choices=["Audio", "Youtube"],
24
+ label="Choose your input type",
25
+ value="Audio",
26
+ )
27
+ audio_input = gr.Audio(
28
+ sources=["upload", "microphone"],
29
+ type="filepath",
30
+ label="Upload Audio, or speak in the microphone",
31
+ visible=True,
32
+ interactive=True,
33
+ )
34
+ youtube_input = gr.Textbox(
35
+ value="https://www.youtube.com/",
36
+ label="Youtube Link",
37
+ visible=False,
38
+ interactive=True,
39
+ )
40
+ btn = gr.Button(
41
+ "Transcript",
42
+ )
43
+ with gr.Column():
44
+ output = gr.Text(label="Model output")
45
 
46
  def make_visible(val):
47
  audio_visible = val == "Audio"
 
52
 
53
  radio.change(make_visible, inputs=radio, outputs=[audio_input, youtube_input])
54
 
55
+ def on_button_click():
56
+ if radio.value == "Audio":
57
+ audio_path = audio_input.value
58
+ else:
59
+ audio_path = dl_youtube_audio(youtube_input.value)
60
+ output.value = transcribe_audio(audio_path)
61
+
62
+ btn.click(
63
+ fn=on_button_click, inputs=[radio, audio_input, youtube_input], outputs=output
64
+ )
65
 
66
  demo.launch()
requirements.txt CHANGED
@@ -1,4 +1,5 @@
1
  transformers
2
  gradio
3
  torch
4
- youtube_dl
 
 
1
  transformers
2
  gradio
3
  torch
4
+ youtube_dl
5
+ pytube