Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,22 +6,30 @@ from transformers import pipeline
|
|
| 6 |
summarizer = pipeline("summarization")
|
| 7 |
|
| 8 |
def generate_summary(video_url):
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
|
|
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
# Create the Gradio interface
|
| 21 |
demo = gr.Interface(
|
| 22 |
-
generate_summary,
|
| 23 |
-
gr.Textbox(label="YouTube Video URL"),
|
| 24 |
-
gr.Textbox(label="Video Summary"),
|
| 25 |
title="AI Video Summarizer",
|
| 26 |
description="Enter a YouTube video URL to generate a summary of the video",
|
| 27 |
)
|
|
|
|
| 6 |
summarizer = pipeline("summarization")
|
| 7 |
|
| 8 |
def generate_summary(video_url):
|
| 9 |
+
try:
|
| 10 |
+
# Get the video title and description from YouTube
|
| 11 |
+
yt = YouTube(video_url)
|
| 12 |
+
title = yt.title
|
| 13 |
+
description = yt.description
|
| 14 |
|
| 15 |
+
# Check if the description is empty
|
| 16 |
+
if not description.strip():
|
| 17 |
+
return "Description is empty. Unable to generate a summary."
|
| 18 |
|
| 19 |
+
# Generate a summary of the video using the AI model
|
| 20 |
+
summary = summarizer(description, max_length=130, min_length=30, do_sample=False)
|
| 21 |
+
|
| 22 |
+
# Return the summary
|
| 23 |
+
return summary[0]["summary_text"]
|
| 24 |
+
|
| 25 |
+
except Exception as e:
|
| 26 |
+
return f"An error occurred: {str(e)}"
|
| 27 |
|
| 28 |
# Create the Gradio interface
|
| 29 |
demo = gr.Interface(
|
| 30 |
+
fn=generate_summary,
|
| 31 |
+
inputs=gr.Textbox(label="YouTube Video URL", placeholder="Enter the URL of the YouTube video"),
|
| 32 |
+
outputs=gr.Textbox(label="Video Summary", lines=5),
|
| 33 |
title="AI Video Summarizer",
|
| 34 |
description="Enter a YouTube video URL to generate a summary of the video",
|
| 35 |
)
|