File size: 919 Bytes
d4317f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

from youtube_transcript_api import YouTubeTranscriptApi
from youtube_transcript_api.formatters import TextFormatter
from transformers import pipeline
import re
import gradio

pipe = pipeline("summarization", model="Falconsai/text_summarization")

def summary(text_transcript):
    output = pipe(text_transcript)
    return output[0]['summary_text']

def get_youtube_transcript(link):
    video_id= extract_youtube_id(link)
    if not video_id:
        return "Video ID could not be extracted"

    try:
        transcript= YouTubeTranscriptApi.get_transcript(video_id) # fetches the trancript

        formatter= TextFormatter()
        text_transcript = formatter.format_transcript(transcript) # This will format the transcript
        
        summarized_text = summary(text_transcript)
        
        return summarized_text
    except Exception as e:
        return f"An error has occured: {e}"