File size: 1,246 Bytes
bc66d6f
fd74d56
 
06534a6
fd74d56
 
 
3a09a61
 
 
 
 
 
 
 
 
 
 
9430119
 
04ab4a3
 
 
 
946d548
9430119
3a09a61
04ab4a3
fd74d56
 
 
 
04ab4a3
fb75041
9430119
 
fd74d56
 
 
 
 
 
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
from pytube import YouTube
from transformers import pipeline
import gradio as gr
import os

pipe = pipeline(model="Yilin98/whisper-small-hi")  # change to "your-username/the-name-you-picked"

def get_audio(url):
  yt = YouTube(url)
  stream = yt.streams.filter(only_audio=True).first()
  out_file=stream.download(output_path=".")
  base, ext = os.path.splitext(out_file)
  new_file = base+'.mp3'
  os.rename(out_file, new_file)
  audio = new_file
  return audio


def transcribe(audio=None, file=None, youtube=None):
    if (audio is None) and (file is None) and (youtube is None):
        return "No audio provided!"
    elif audio is not None:
        input=audio
    elif file is not None:
        input=file
    elif youtube is not None:
        input=get_audio(youtube)
    text = pipe(input)["text"]
    return text

iface = gr.Interface(
    fn=transcribe, 
    inputs=[
        gr.Audio(source="microphone", type="filepath", interactive=True),
        gr.Audio(source="upload", type="filepath", interactive=True),
        gr.Text(label="URL (YouTube, etc.)")], 
    outputs="text",
    title="Whisper Small Swedish",
    description="Realtime demo for Swedish speech recognition using a fine-tuned Whisper small model.",
)

iface.launch()