File size: 1,819 Bytes
356bab3
5d6bc67
949b582
 
93d849e
949b582
 
 
79348af
356bab3
a952e20
 
949b582
356bab3
949b582
 
d9c9d47
 
 
 
 
 
 
 
 
949b582
 
d9c9d47
949b582
d9c9d47
949b582
 
d9c9d47
949b582
 
 
 
 
d9c9d47
 
 
 
949b582
356bab3
 
 
 
949b582
356bab3
949b582
 
 
 
 
356bab3
 
949b582
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
import gradio as gr
import os
from pytubefix import YouTube
from moviepy.editor import VideoFileClip
from transformers import pipeline

# Load Whisper model for transcription
asr = pipeline("automatic-speech-recognition", model="distil-whisper/distil-small.en")

# Load Summarization model
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")

def process_youtube_link(youtube_url):
    try:
        # Download YouTube Video
        yt = YouTube(youtube_url)
        title = yt.title
        print(f"Downloading: {title}")

        video_stream = yt.streams.get_highest_resolution()
        if not video_stream:
            return "Error: No available video stream", ""

        video_path = f"{title}.mp4"
        video_stream.download(filename=video_path)

        # Extract Audio
        audio_path = f"{title}.wav"
        video = VideoFileClip(video_path)
        video.audio.write_audiofile(audio_path, codec="pcm_s16le")

        # Transcribe Audio
        transcription = asr(audio_path, return_timestamps=True)
        transcribed_text = transcription["text"]

        # Summarize Transcription
        summary = summarizer(transcribed_text, max_length=150, min_length=50, do_sample=False)[0]["summary_text"]

        # Clean up files after processing
        os.remove(video_path)
        os.remove(audio_path)

        return transcribed_text, summary

    except Exception as e:
        return f"Error: {str(e)}", ""

# Create Gradio Interface
iface = gr.Interface(
    fn=process_youtube_link,
    inputs=gr.Textbox(label="Enter YouTube URL"),
    outputs=[gr.Textbox(label="Transcription"), gr.Textbox(label="Summary")],
    title="YouTube Video Transcriber & Summarizer",
    description="Enter a YouTube link, and this app will transcribe and summarize the audio.",
)

iface.launch()