Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,43 @@
|
|
1 |
from transformers import pipeline
|
2 |
import gradio as gr
|
|
|
3 |
|
4 |
pipe = pipeline(model="Hoft/whisper-small-swedish-asr") # change to "your-username/the-name-you-picked"
|
5 |
|
6 |
-
def
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
outputs="text",
|
20 |
title="Whisper Small Swedish",
|
21 |
description="Realtime demo for Swedish speech recognition using a fine-tuned Whisper small model.",
|
22 |
)
|
23 |
|
|
|
|
|
24 |
|
25 |
-
|
|
|
1 |
from transformers import pipeline
|
2 |
import gradio as gr
|
3 |
+
import pytube as pt
|
4 |
|
5 |
pipe = pipeline(model="Hoft/whisper-small-swedish-asr") # change to "your-username/the-name-you-picked"
|
6 |
|
7 |
+
def microphone_transcribe(audio):
|
8 |
+
text = pipe(audio)["text"]
|
9 |
+
return text
|
10 |
+
|
11 |
+
def youtube_transcribe(url):
|
12 |
+
yt_url = pt.YouTube(url)
|
13 |
+
|
14 |
+
stream = yt.streams.filter(only_audio=True)[0]
|
15 |
+
stream.download(filename="audio.mp3")
|
16 |
+
|
17 |
+
text = pipe("audio.mp3")["text"]
|
18 |
+
|
19 |
+
return text
|
20 |
+
|
21 |
+
|
22 |
+
app = gr.Blocks()
|
23 |
+
|
24 |
+
microphone_tab = gr.Interface(
|
25 |
+
fn=microphone_transcribe,
|
26 |
+
inputs=gr.Audio(source="microphone", type="filepath"),
|
27 |
+
outputs="text",
|
28 |
+
title="Whisper Small Swedish",
|
29 |
+
description="Realtime demo for Swedish speech recognition using a fine-tuned Whisper small model.",
|
30 |
+
)
|
31 |
+
|
32 |
+
youtube_tab = gr.Interface(
|
33 |
+
fn=youtube_transcribe,
|
34 |
+
inputs=[gr.inputs.Textbox(lines=1, placeholder="Paste the URL to a YouTube video", label="URL")],
|
35 |
outputs="text",
|
36 |
title="Whisper Small Swedish",
|
37 |
description="Realtime demo for Swedish speech recognition using a fine-tuned Whisper small model.",
|
38 |
)
|
39 |
|
40 |
+
with app:
|
41 |
+
gr.TabbedInterface([microphone_tab, youtube_tab], ["Microphone", "YouTube"])
|
42 |
|
43 |
+
app.launch(enable_queue=True)
|