File size: 1,351 Bytes
7d13f08
 
5b077dd
e559252
7d13f08
e559252
7d13f08
e559252
 
7d13f08
 
e559252
 
 
 
8e990cb
 
e559252
 
 
 
 
 
 
 
 
 
a062548
e559252
 
 
 
 
 
a062548
 
e559252
 
 
 
 
 
 
a062548
e559252
ba60c22
7d13f08
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from transformers import pipeline
import gradio as gr
from pytube import YouTube
import os

pipe = pipeline(model="CsanadT/whisper_small_sv")

def transcribe_live(audio):
    text = pipe(audio)["text"]
    return text

def transcribe_url(url):
    youtube = YouTube(str(url))
    audio = youtube.streams.filter(only_audio=True).first().download('yt_video')
    text = pipe(audio)["text"]
    return text

def transcribe_file(audio):
    rate, y = audio
    text = pipe(y)["text"]
    return text

url_demo = gr.Interface(
    fn = transcribe_url, 
    inputs = "text", 
    outputs = "text",
    title = "Swedish Whisper",
    description = "Transciption of a swedish YouTube video via a fine-tuned Whisper model",
)

voice_demo = gr.Interface(
    fn=transcribe_live, 
    inputs=gr.Audio(source="microphone", type="filepath"), 
    outputs="text",
    title="Swedish Whisper",
    description="Live transcription of swedish speech via a fine-tuned Whisper model",
)

file_demo = gr.Interface(
    fn = transcribe_file,
    inputs=gr.Audio(file_count="single"),
    outputs="text",
    title="Swedish Whisper",
    description="Transciption of a swedish audio file via a fine-tuned Whisper model",
)
demo = gr.TabbedInterface([url_demo, voice_demo, file_demo], ["YouTube video transciption", "Live audio to Text", "Transcribe a file"])

demo.launch()