Spaces:
Sleeping
Sleeping
youtube links
Browse files
app.py
CHANGED
@@ -1,14 +1,47 @@
|
|
1 |
from transformers import pipeline
|
2 |
import gradio as gr
|
|
|
3 |
|
4 |
-
model = pipeline(model="SofiaK/checkpoints")
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
outputs=gr.Text(label="Model output"),
|
10 |
title="Whisper-RU",
|
11 |
description="Fine-tuned Whisper for Russian language",
|
12 |
)
|
13 |
|
14 |
-
|
|
|
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 |
+
# Function to transcribe audio
|
24 |
+
def transcribe_audio(audio_path):
|
25 |
+
model = pipeline(model="SofiaK/checkpoints")
|
26 |
+
return model(audio_path)["text"]
|
27 |
+
|
28 |
+
|
29 |
+
interface = gr.Interface(
|
30 |
+
fn=lambda input_type, audio_or_link: transcribe_audio(audio_or_link)
|
31 |
+
if input_type == "audio"
|
32 |
+
else transcribe_audio(download_audio(audio_or_link, "temp.mp3")),
|
33 |
+
inputs=[
|
34 |
+
gr.Radio(["audio", "youtube"], label="Select Input Type"),
|
35 |
+
gr.Audio(
|
36 |
+
sources=["upload", "microphone"],
|
37 |
+
type="filepath",
|
38 |
+
label="Upload Audio, or speak in the microphone",
|
39 |
+
),
|
40 |
+
gr.Textbox(default="https://www.youtube.com/", label="Youtube Link"),
|
41 |
+
],
|
42 |
outputs=gr.Text(label="Model output"),
|
43 |
title="Whisper-RU",
|
44 |
description="Fine-tuned Whisper for Russian language",
|
45 |
)
|
46 |
|
47 |
+
interface.launch(share=True)
|