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()[0].download('yt_video') text = pipe(audio)["text"] return text tts_examples = [ "I love learning machine learning", "How do you do?", ] url_demo = gr.Interface( fn=transcribeUrl, inputs="text", outputs="text") 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([url_demo, voice_demo], ["Text-to-speech", "Speech-to-text"]) if __name__ == "__main__": demo.launch()