irena commited on
Commit
fbeec50
·
1 Parent(s): bc4b2de

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from transformers import pipeline
4
+ from pytube import YouTube
5
+
6
+
7
+ pipe = pipeline(model="irena/whisper-small-sv-SE")
8
+
9
+
10
+ def yt(link):
11
+ yt = YouTube(link)
12
+ stream = yt.streams.filter(only_audio=True)[0]
13
+ stream.download(filename="audio.mp3")
14
+ text = pipe("audio.mp3")["text"]
15
+ return text
16
+
17
+ def transcribe(audio):
18
+ text = pipe(audio)["text"]
19
+ return text
20
+
21
+ demo = gr.Blocks()
22
+
23
+
24
+ iface = gr.Interface(
25
+ fn=transcribe,
26
+ inputs=gr.Audio(source="microphone", type="filepath"),
27
+ outputs="text",
28
+ title="Whisper Small Swedish-Microphone",
29
+ description="Realtime demo for Swedish speech recognition using a fine-tuned Whisper small model. An audio for recognize.",
30
+ )
31
+
32
+ yt = gr.Interface(
33
+ fn=yt,
34
+ inputs=[gr.inputs.Textbox(lines=1, label="Youtube URL")],
35
+ outputs=["html", "text"],
36
+ title="Whisper Small Swedish-Youtube",
37
+ description="Realtime demo for Swedish speech recognition using a fine-tuned Whisper small model. A Youtube URL for recognize."
38
+
39
+ )
40
+
41
+ with demo:
42
+ gr.TabbedInterface([iface, yt], ["Transcribe Audio", "Transcribe YouTube"])
43
+
44
+ demo.launch(enable_queue=True)