Videoch / app.py
Doubleupai's picture
Update app.py
3784116 verified
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()