Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from tqdm import tqdm
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
from IPython.display import YouTubeVideo
|
| 5 |
+
from youtube_transcript_api import YouTubeTranscriptApi
|
| 6 |
+
|
| 7 |
+
def video2Summarizer(link):
|
| 8 |
+
youtube_video = link
|
| 9 |
+
video_id = youtube_video.split('=')[1]
|
| 10 |
+
transcript = YouTubeTranscriptApi.get_transcript(video_id)
|
| 11 |
+
|
| 12 |
+
result = ""
|
| 13 |
+
for i in transcript:
|
| 14 |
+
result += ' ' + i['text']
|
| 15 |
+
|
| 16 |
+
summarizer = pipeline('summarization')
|
| 17 |
+
|
| 18 |
+
num_iters = int(len(result)/1000)
|
| 19 |
+
summarized_text = []
|
| 20 |
+
for i in tqdm(range(0, num_iters + 1)):
|
| 21 |
+
start = 0
|
| 22 |
+
start = i * 1000
|
| 23 |
+
end = (i + 1) * 1000
|
| 24 |
+
out = summarizer(result[start:end])
|
| 25 |
+
out = out[0]
|
| 26 |
+
out = out['summary_text']
|
| 27 |
+
summarized_text.append(out)
|
| 28 |
+
|
| 29 |
+
return summarized_text
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
iface = gr.Interface(fn = video2Summarizer,
|
| 33 |
+
inputs = 'text',
|
| 34 |
+
outputs = gr.outputs.Textbox(label = "Summarized output"),
|
| 35 |
+
title = 'Video To Text Summarizer',
|
| 36 |
+
description = 'Just give the url of the YouTube video, then the app will give you the summarized format of the video in 5 to 10 Min, its based on the video length what you have given. Use this example and try to run the same example by clicking that',
|
| 37 |
+
examples = [['https://www.youtube.com/watch?v=kEN2Omq9mwk']]
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
iface.launch(inline = False)
|