File size: 1,974 Bytes
d9dcfce
d4abdb4
 
 
e0dd3a0
d4abdb4
e0dd3a0
e344fd6
 
 
 
95d373f
e344fd6
 
 
bc07ca5
e344fd6
 
 
d4abdb4
e344fd6
4048d8a
85374d0
e344fd6
 
96ddf3a
e344fd6
85374d0
 
e344fd6
 
 
 
 
 
 
 
 
 
96ddf3a
 
 
 
 
 
 
e344fd6
96ddf3a
e3a8693
e344fd6
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
43
44
45
46
47
48
49
50
from transformers import pipeline
import gradio as gr
from pytube import YouTube

pipe = pipeline(model="Mei000/whisper-small-sv-SE")

      
def link_transcribe(link):
  path = YouTube(link).streams.filter(only_audio=True)[0].download(filename="tmp.mp4")
  results_text = pipe(path)["text"]
  return results_text
      
def transcribe(audio):
  text = pipe(audio)["text"]
  return text

def populate_metadata(link):
  lin = YouTube(link)
  return lin.thumbnail_url, lin.title

with gr.Blocks() as demo:

    gr.Markdown("Whisper Small Swedish")
    with gr.Row():
        with gr.TabItem("Record from Microphone"):
            record_input = gr.Audio(source="microphone", type="filepath",label="Record from microphone")
            record_button = gr.Button("Submit")
            record_outputs = [gr.Textbox(label="Transcription from Microphone"),] 

    with gr.Row().style(equal_height=True):
        link = gr.Textbox(label="YouTube Link")
        title = gr.Label(label="Video Title")
    with gr.Row().style(equal_height=True):
        img = gr.Image(label="Thumbnail")
        youtube_outputs = [
                gr.Textbox(label="Transcription", placeholder="Transcription Output", lines=10)
            ]         
    with gr.Row().style(equal_height=True):
        youtube_button = gr.Button("Submit")
    with gr.Row():
        with gr.TabItem("Audio File"):
            offline_file = gr.Audio(source="upload", type="filepath",label="Upload An Audio File")
            offline_upload = gr.Button("Submit")
            offline_outputs = [gr.Textbox(label="Transcription from uploaded audio file"),]
            
    record_button.click( fn=transcribe, inputs=record_input, outputs=record_outputs,)   
    youtube_button.click( fn=link_transcribe, inputs=link, outputs=youtube_outputs,)
    offline_upload.click( fn=transcribe, inputs=offline_file, outputs=offline_outputs,)
    link.change(fn=populate_metadata, inputs=[link], outputs=[img, title])
demo.launch()