Spaces:
Running
Running
Delete app.py
Browse files
app.py
DELETED
@@ -1,47 +0,0 @@
|
|
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 |
-
def summary (input):
|
11 |
-
output = text_summary(input)
|
12 |
-
return output[0]['summary_text']
|
13 |
-
|
14 |
-
def extract_video_id(url):
|
15 |
-
# Regex to extract the video ID from various YouTube URL formats
|
16 |
-
regex = r"(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})"
|
17 |
-
match = re.search(regex, url)
|
18 |
-
if match:
|
19 |
-
return match.group(1)
|
20 |
-
return None
|
21 |
-
|
22 |
-
|
23 |
-
def get_youtube_transcript(video_url):
|
24 |
-
video_id = extract_video_id(video_url)
|
25 |
-
if not video_id:
|
26 |
-
return "Video ID could not be extracted."
|
27 |
-
|
28 |
-
try:
|
29 |
-
# Fetch the transcript
|
30 |
-
transcript = YouTubeTranscriptApi.get_transcript(video_id)
|
31 |
-
|
32 |
-
# Format the transcript into plain text
|
33 |
-
formatter = TextFormatter()
|
34 |
-
text_transcript = formatter.format_transcript(transcript)
|
35 |
-
summary_text = summary(text_transcript)
|
36 |
-
|
37 |
-
return summary_text
|
38 |
-
except Exception as e:
|
39 |
-
return f"An error occurred: {e}"
|
40 |
-
|
41 |
-
gr.close_all()
|
42 |
-
demo = gr.Interface(fn=get_youtube_transcript,
|
43 |
-
inputs=[gr.Textbox(label="Input YouTube Url to summarize",lines=1)],
|
44 |
-
outputs=[gr.Textbox(label="Summarized text",lines=4)],
|
45 |
-
title="YouTube Script Summarizer ",
|
46 |
-
description="THIS APPLICATION WILL BE USED TO SUMMARIZE THE YOUTUBE VIDEO SCRIPT.")
|
47 |
-
demo.launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|