Spaces:
Build error
Build error
adjoint-bass
commited on
Commit
•
e559252
1
Parent(s):
556e022
update app.py
Browse files
app.py
CHANGED
@@ -1,38 +1,48 @@
|
|
1 |
from transformers import pipeline
|
2 |
import gradio as gr
|
3 |
from pytube import YouTube
|
|
|
4 |
|
5 |
-
pipe = pipeline(model
|
6 |
|
7 |
-
def
|
8 |
-
text = pipe(audio)[
|
9 |
return text
|
10 |
|
11 |
-
def
|
12 |
-
|
13 |
-
audio=
|
14 |
-
text = pipe(audio)[
|
15 |
return text
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
demo.launch()
|
|
|
1 |
from transformers import pipeline
|
2 |
import gradio as gr
|
3 |
from pytube import YouTube
|
4 |
+
import os
|
5 |
|
6 |
+
pipe = pipeline(model="CsanadT/whisper_small_sv")
|
7 |
|
8 |
+
def transcribe_live(audio):
|
9 |
+
text = pipe(audio)["text"]
|
10 |
return text
|
11 |
|
12 |
+
def transcribe_url(url):
|
13 |
+
youtube = YouTube(str(url))
|
14 |
+
audio = youtube.streams.filter(only_audio=True).first().download('yt_video')
|
15 |
+
text = pipe(audio)["text"]
|
16 |
return text
|
17 |
|
18 |
+
def transcribe_file(audio):
|
19 |
+
rate, y = audio
|
20 |
+
text = pipe(y)["text"]
|
21 |
+
return text
|
22 |
+
|
23 |
+
url_demo = gr.Interface(
|
24 |
+
fn = transcribe_url,
|
25 |
+
inputs = "text",
|
26 |
+
outputs = "text",
|
27 |
+
title = "Swedish Whisper",
|
28 |
+
description = "Fine-tuned Whisper model for swedish audio transcription",
|
29 |
+
)
|
30 |
+
|
31 |
+
voice_demo = gr.Interface(
|
32 |
+
fn=transcribe_live,
|
33 |
+
inputs=gr.Audio(source="microphone", type="filepath"),
|
34 |
+
outputs="text",
|
35 |
+
title="Whisper Swedish",
|
36 |
+
description="Fine-tuned Whisper model for swedish audio transcription",
|
37 |
+
)
|
38 |
+
|
39 |
+
file_demo = gr.Interface(
|
40 |
+
fn = transcribe_file,
|
41 |
+
inputs=gr.Audio(file_count="single"),
|
42 |
+
outputs="text",
|
43 |
+
title="Swedish Whisper",
|
44 |
+
description="Fine-tuned Whisper model for swedish audio transcription",
|
45 |
+
)
|
46 |
+
demo = gr.TabbedInterface([url_demo, voice_demo, file_demo], ["YouTube Video to Text", "Audio to Text"])
|
47 |
|
48 |
demo.launch()
|