from transformers import pipeline import gradio as gr from pytube import YouTube import os pipe = pipeline(model="afroanton/whisper-small-sv-SE") # change to "your-username/the-name-you-picked" def transcribe(audio): text = pipe(audio)["text"] return text def transcribeUrl(url): yt = YouTube(str(url)) audio = yt.streams.filter(only_audio=True).first() text = pipe(audio)["text"] return text video_demo = gr.Interface.load( fn=transcribeUrl, inputs=gr.Textbox( label="insert URL", lines=3, value="The fast brown fox jumps over lazy dogs.", ), outputs="text", title="Whisper Small Swedish", description="Realtime demo for Swedish speech recognition using a fine-tuned Whisper small model.", ) voice_demo = gr.Interface( fn=transcribe, inputs=gr.Audio(source="microphone", type="filepath"), outputs="text", title="Whisper Small Swedish", description="Realtime demo for Swedish speech recognition using a fine-tuned Whisper small model.", ) demo = gr.TabbedInterface([voice_demo, video_demo], ["voice to text", "video to text"]) demo.launch()