Spaces:
Sleeping
Sleeping
changes in ui
Browse files- app.py +45 -48
- requirements.txt +2 -1
app.py
CHANGED
@@ -1,58 +1,47 @@
|
|
1 |
from transformers import pipeline
|
2 |
import gradio as gr
|
3 |
-
from
|
4 |
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
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 |
-
|
24 |
-
|
25 |
-
|
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 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
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 |
-
|
67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|