File size: 1,756 Bytes
8259c89 45b350f 2b8c3b8 8259c89 05269d6 4180601 8259c89 4180601 271b435 399dcbe 05269d6 c3a2549 23ee19b 96a3f15 8259c89 23ee19b 96a3f15 23ee19b 96a3f15 23ee19b 2b94ee6 23ee19b 2b94ee6 23ee19b 714b606 2b94ee6 8259c89 2b94ee6 8259c89 2b94ee6 8259c89 2b94ee6 | 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 | from transformers import pipeline
from youtube_transcript_api import YouTubeTranscriptApi, NoTranscriptFound, VideoUnavailable
import gradio as gr
summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
def get_videoID(url):
if "v=" in url:
return url.split("v=")[1].split("&")[0]
elif "youtu.be/" in url:
return url.split("youtu.be/")[1].split("?")[0]
else:
return None
def get_transcripts(videoID):
try:
transcript_list = YouTubeTranscriptApi.get_transcript(videoID)
texts = [t['text'] for t in transcript_list]
transcript = " ".join(texts)
return transcript
except Exception as e:
return "Code worked fine, but transcripts cannot be fetched due to free version of hugging face"
def summaryOfTranscript(url):
videoId = get_videoID(url)
if videoId is None:
return "Invalid Youtube URL"
trans = get_transcripts(videoId)
if trans == "Code worked fine, but transcripts cannot be fetched due to free version of hugging face":
return trans
if not trans or len(trans.split()) < 30:
return "Transcript is too short to be summarized."
try:
summary = summarizer(trans[:2000], max_length=150, min_length=30, do_sample=False)
return summary[0]['summary_text']
except Exception:
return "Code worked fine, but summarization failed for this transcript."
iface = gr.Interface(
fn=summaryOfTranscript,
inputs=gr.Textbox(lines=1, placeholder="Enter Youtube URL here"),
outputs="text",
title="Youtube Video Summariser",
description="Enter the URL of the YouTube video and get a quick summary of it!"
)
iface.launch()
|