Spaces:
Sleeping
Sleeping
changes in ui
Browse files
app.py
CHANGED
@@ -4,44 +4,66 @@ from youtube_dl import YoutubeDL
|
|
4 |
|
5 |
|
6 |
# Function to download audio from YouTube link
|
7 |
-
def download_audio(youtube_link, output_path):
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
#
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
interface
|
30 |
-
|
31 |
-
if input_type == "
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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"
|
59 |
+
return {
|
60 |
+
audio_input: {"visible": audio_visible, "__type__": "update"},
|
61 |
+
youtube_input: {"visible": not audio_visible, "__type__": "update"},
|
62 |
+
}
|
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()
|