File size: 1,343 Bytes
61ceeef
 
087f485
61ceeef
db29542
8839ec0
61ceeef
8839ec0
 
d5c74e2
29623d8
8839ec0
61ceeef
821ae6c
9e831b2
821ae6c
 
 
6d1b0e7
 
087f485
b922546
6d1b0e7
 
 
087f485
29623d8
6d1b0e7
 
 
 
 
 
d9d1a87
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
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

def transcribe_and_translate_yt(link):
    yt = YouTube(link)
    audio = yt.streams.filter(only_audio=True).first().download()

    return transcribe_and_translate(audio)
    
with gr.Blocks() as demo:
    with gr.Tab("Real-time Swedish to English Transcription and Translation"):
        audio = gr.Audio(sources=["microphone", "upload"], type="filepath")
        rt_outputs = [gr.Textbox(), gr.Textbox()]
        rt_button = gr.Button('Transcribe and Translate')

    with gr.Tab("Youtube Video Transcription and Translation"):
        link = gr.Textbox(label="Enter YouTube Video Link")
        yt_outputs = [gr.Textbox(), gr.Textbox()]
        yt_button = gr.Button('Transcribe and Translate YouTube Video')

    rt_button.click(transcribe_and_translate, inputs=audio, outputs=rt_outputs)
    yt_button.click(transcribe_and_translate_yt, inputs=link, outputs=yt_outputs)
        
demo.launch(debug=True)