File size: 2,654 Bytes
87359bb
69bf66b
 
87359bb
69bf66b
 
 
 
 
 
651ae26
 
 
 
 
 
 
87359bb
e31036d
651ae26
 
87359bb
e31036d
4f26484
 
 
 
 
 
 
 
 
 
87359bb
e31036d
651ae26
e31036d
651ae26
87359bb
651ae26
e31036d
651ae26
 
 
 
 
 
 
 
 
 
 
 
 
e31036d
651ae26
e31036d
 
 
651ae26
 
e31036d
 
87359bb
e31036d
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
56
57
58
59
60
61
62
63
64
65
66
import whisper
from pytube import YouTube
from transformers import pipeline
import gradio as gr
import os

model = whisper.load_model("base")
summarizer = pipeline("summarization")

def get_audio(url):
    yt = YouTube(url)
    video = yt.streams.filter(only_audio=True).first()
    out_file = video.download(output_path=".")
    base, ext = os.path.splitext(out_file)
    new_file = base + '.mp3'
    os.rename(out_file, new_file)
    return new_file

def get_text_from_url(url):
    result = model.transcribe(get_audio(url))
    return result['text']

def get_text_from_file(file_path):
    # Extract audio from the MP4 file
    video = VideoFileClip(file_path)
    audio_path = file_path.replace(".mp4", ".mp3")
    video.audio.write_audiofile(audio_path)
    # Transcribe the audio
    result = model.transcribe(audio_path)
    # Optionally, remove the audio file after transcription
    os.remove(audio_path)
    return result['text']
    
def get_summary(url):
    article = get_text_from_url(url)
    b = summarizer(article)
    return b[0]['summary_text']

with gr.Blocks() as demo:
    gr.Markdown("<h1><center>Youtube video transcription with OpenAI's Whisper</center></h1>")
    gr.Markdown("<center>Enter the link of any youtube video or upload an MP4 file to get the transcription of the video and a summary of the video in the form of text.</center>")
    
    with gr.Tab('Get the transcription of any Youtube video'):
        with gr.Row():
            input_text_1 = gr.Textbox(placeholder='Enter the Youtube video URL', label='URL')
            output_text_1 = gr.Textbox(placeholder='Transcription of the video', label='Transcription')
        result_button_1 = gr.Button('Get Transcription')
    
    with gr.Tab('Summary of Youtube video'):
        with gr.Row():
            input_text = gr.Textbox(placeholder='Enter the Youtube video URL', label='URL')
            output_text = gr.Textbox(placeholder='Summary text of the Youtube Video', label='Summary')
        result_button = gr.Button('Get Summary')
    
    with gr.Tab('Upload MP4 for Transcription'):
        with gr.Row():
            input_file = gr.File(label="Upload MP4 File", type=["mp4"])
            output_text_file = gr.Textbox(placeholder='Transcription of the uploaded video', label='Transcription')
        result_button_file = gr.Button('Get Transcription from File')
    
    result_button.click(get_summary, inputs=input_text, outputs=output_text)
    result_button_1.click(get_text_from_url, inputs=input_text_1, outputs=output_text_1)
    result_button_file.click(get_text_from_file, inputs=input_file, outputs=output_text_file)

demo.launch(debug=True)