Kunal Zaveri commited on
Commit
7ab4bb3
1 Parent(s): 651aba4

uploading the file

Browse files
Files changed (1) hide show
  1. app.py +53 -0
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ from youtube_transcript_api import YouTubeTranscriptApi
3
+ from youtube_transcript_api.formatters import TextFormatter
4
+ import torch
5
+ import gradio as gr
6
+ from transformers import pipeline
7
+
8
+ # text_summary = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6", torch_dtype=torch.bfloat16)
9
+
10
+ text_summary = pipeline("summarization", model="Falconsai/text_summarization")
11
+
12
+ def summary(input):
13
+ output = text_summary(input)
14
+ return output[0]['summary_text']
15
+
16
+
17
+ def extract_video_id(url):
18
+ # Regex to extract the video ID from various YouTube URL formats
19
+ regex = r"(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})"
20
+ match = re.search(regex, url)
21
+ if match:
22
+ return match.group(1)
23
+ return None
24
+
25
+
26
+ def get_youtube_transcript(video_url):
27
+ video_id = extract_video_id(video_url)
28
+ if not video_id:
29
+ return "Video ID could not be extracted."
30
+
31
+ try:
32
+ # Fetch the transcript
33
+ transcript = YouTubeTranscriptApi.get_transcript(video_id)
34
+
35
+ # Format the transcript into plain text
36
+ formatter = TextFormatter()
37
+ text_transcript = formatter.format_transcript(transcript)
38
+ summary_text = summary(text_transcript)
39
+
40
+ return summary_text
41
+ except Exception as e:
42
+ return f"An error occurred: {e}"
43
+
44
+
45
+ gr.close_all()
46
+
47
+ # demo = gr.Interface(fn=summary, inputs="text",outputs="text")
48
+ demo = gr.Interface(fn=get_youtube_transcript,
49
+ inputs=[gr.Textbox(label="Input YouTube Url to summarize", lines=1)],
50
+ outputs=[gr.Textbox(label="Summarized text", lines=4)],
51
+ title="@GenAILearniverse Project 2: YouTube Script Summarizer",
52
+ description="THIS APPLICATION WILL BE USED TO SUMMARIZE THE YOUTUBE VIDEO SCRIPT.")
53
+ demo.launch()