File size: 1,253 Bytes
51c2bdb
 
 
 
 
 
 
 
3784116
 
 
 
 
51c2bdb
3784116
 
 
51c2bdb
3784116
 
 
 
 
 
 
 
51c2bdb
 
 
3784116
 
 
51c2bdb
 
 
 
 
 
 
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
import gradio as gr
from pytube import YouTube
from transformers import pipeline

# Initialize the pipeline for video summary generation
summarizer = pipeline("summarization")

def generate_summary(video_url):
    try:
        # Get the video title and description from YouTube
        yt = YouTube(video_url)
        title = yt.title
        description = yt.description

        # Check if the description is empty
        if not description.strip():
            return "Description is empty. Unable to generate a summary."

        # Generate a summary of the video using the AI model
        summary = summarizer(description, max_length=130, min_length=30, do_sample=False)

        # Return the summary
        return summary[0]["summary_text"]
    
    except Exception as e:
        return f"An error occurred: {str(e)}"

# Create the Gradio interface
demo = gr.Interface(
    fn=generate_summary,
    inputs=gr.Textbox(label="YouTube Video URL", placeholder="Enter the URL of the YouTube video"),
    outputs=gr.Textbox(label="Video Summary", lines=5),
    title="AI Video Summarizer",
    description="Enter a YouTube video URL to generate a summary of the video",
)

# Launch the Gradio application
if __name__ == "__main__":
    demo.launch()