File size: 1,324 Bytes
4806866
 
 
 
899b28d
4806866
619d335
361924b
4806866
361924b
4806866
 
619d335
361924b
4806866
 
 
619d335
4806866
619d335
4806866
619d335
4806866
d7ece34
4806866
c196faa
 
24435a2
 
 
 
 
 
 
c196faa
 
 
 
 
 
 
 
 
 
 
 
 
 
361924b
c196faa
 
4806866
 
 
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
51
52
53
54
55
import gradio as gr
import whisper
import os

model = whisper.load_model("base")

# main processing
def main(URL):
    video_path = youtube_dl(URL)
    text = transcript(video_path)
    return text

# Transcribe text using Whisper
def transcript(video_path):
    result = model.transcribe(video_path)
    return result["text"]

# Download the video
def youtube_dl(URL):
    # Download the video
    os.system(f"yt-dlp -f best -v {URL} -o target.mp4")
    # Path of downloaded video
    video_path = os.path.join(os.path.dirname(__file__), "target.mp4")
    return video_path

with gr.Blocks() as demo:

    gr.Markdown(
    """
    # YouTube video transcription app
    Enter the YouTube URL, press the button, and it will transcribe the video.
    """
    )
    
    with gr.Row():

        with gr.Column():

            with gr.Row():
                url = gr.Textbox(placeholder = 'Youtube video URL', label = 'URL')

            with gr.Row():
                transcribe_btn = gr.Button('Transcribe')

        with gr.Column():
            outputs = gr.Textbox(placeholder = 'Transcription of the video', label = 'Transcription')

    transcribe_btn.click(fn = main,
                        inputs = url,
                        outputs = outputs
                        )

if __name__ == "__main__":
    demo.launch()