Spaces:
Runtime error
Runtime error
Commit
·
0d5f601
1
Parent(s):
09648b7
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
from youtube_transcript_api import YouTubeTranscriptApi
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from gradio.mix import Series
|
| 5 |
+
|
| 6 |
+
def summarize_transcript(url):
|
| 7 |
+
video_id = url.split("=")[1]
|
| 8 |
+
|
| 9 |
+
transcript = YouTubeTranscriptApi.get_transcript(video_id)
|
| 10 |
+
|
| 11 |
+
result = ""
|
| 12 |
+
for i in transcript:
|
| 13 |
+
result += ' ' + i['text']
|
| 14 |
+
print(len(result))
|
| 15 |
+
|
| 16 |
+
summarizer = pipeline('summarization')
|
| 17 |
+
|
| 18 |
+
num_iters = int(len(result)/1000)
|
| 19 |
+
summarized_text = []
|
| 20 |
+
for i in range(0, num_iters + 1):
|
| 21 |
+
start = 0
|
| 22 |
+
start = i * 1000
|
| 23 |
+
end = (i + 1) * 1000
|
| 24 |
+
print("input text \n" + result[start:end])
|
| 25 |
+
out = summarizer(result[start:end])
|
| 26 |
+
out = out[0]
|
| 27 |
+
out = out['summary_text']
|
| 28 |
+
print("Summarized text\n"+out)
|
| 29 |
+
summarized_text.append(out)
|
| 30 |
+
summ = str(summarized_text)
|
| 31 |
+
print(summ)
|
| 32 |
+
|
| 33 |
+
return summ
|
| 34 |
+
|
| 35 |
+
gradio_ui = gr.Interface(fn = summarize_transcript,
|
| 36 |
+
inputs = gr.inputs.Textbox(label = "Enter the YouTube URL below:"),
|
| 37 |
+
outputs = gr.outputs.Textbox(label = "Transcript Summary"),
|
| 38 |
+
title = "YouTube Transcript Summarizer",
|
| 39 |
+
theme = "grass",
|
| 40 |
+
description = "Here You can see the summary of the you tube video you want to watch")
|
| 41 |
+
|
| 42 |
+
gradio_ui.launch(inline = False)
|