File size: 1,474 Bytes
61ceeef
 
087f485
61ceeef
1a268a3
8839ec0
61ceeef
8839ec0
 
 
d5c74e2
8839ec0
61ceeef
087f485
 
 
 
 
 
 
 
 
61ceeef
087f485
 
 
 
 
 
 
 
 
 
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
from transformers import pipeline
import gradio as gr
from pytube import YouTube

transcription_pipe = pipeline(model="explorall/whisper-small-sv-dropout-6mb")  
translation_pipe = pipeline(model="Helsinki-NLP/opus-mt-sv-en")


def transcribe_and_translate(audio):
    transcription = transcription_pipe(audio)["text"]
    translation = translation_pipe(transcription)[0]['translation_text']
    return transcription, translation

with gr.Blocks() as demo:
    with gr.Tab("Real-time Swedish to English Transcription and Translation"):
        gr.Interface(
            fn=transcribe_and_translate,
            inputs=gr.Audio(source="microphone", type="filepath"),
            outputs=[gr.Textbox(), gr.Textbox()],
            title="Whisper Small Swedish to English Translator",
            description="Realtime demo for Swedish speech recognition using a fine-tuned Whisper small model, and Swedish to English translation using a small T5 model",
        )

    with gr.Tab("Youtube Video Transcription and Translation"):
       gr.Interface(
            fn=transcribe_and_translate,
            inputs=gr.Audio(source="microphone", type="filepath"),
            outputs=[gr.Textbox(), gr.Textbox()],
            title="Whisper Small Swedish to English Translator",
            description="Realtime demo for Swedish speech recognition using a fine-tuned Whisper small model, and Swedish to English translation using a small T5 model",
        )

demo.launch(debug=True)