Spaces:
Runtime error
Runtime error
owaiskha9654
commited on
Commit
·
0903baf
1
Parent(s):
0789119
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
from youtube_transcript_api import YouTubeTranscriptApi
|
3 |
+
|
4 |
+
def summarize(youtube_video):
|
5 |
+
|
6 |
+
video_id = youtube_video.split("=")[1]
|
7 |
+
transcript = YouTubeTranscriptApi.get_transcript(video_id)
|
8 |
+
|
9 |
+
summarizer = pipeline('summarization')
|
10 |
+
|
11 |
+
result = ""
|
12 |
+
for i in transcript:
|
13 |
+
result += ' ' + i['text']
|
14 |
+
|
15 |
+
num_iters = int(len(result)/1000)
|
16 |
+
summarized_text = []
|
17 |
+
for i in range(0, num_iters + 1):
|
18 |
+
start = 0
|
19 |
+
start = i * 1000
|
20 |
+
end = (i + 1) * 1000
|
21 |
+
print("input text \n" + result[start:end])
|
22 |
+
out = summarizer(result[start:end])
|
23 |
+
out = out[0]
|
24 |
+
out = out['summary_text']
|
25 |
+
print("Summarized text\n"+out)
|
26 |
+
summarized_text.append(out)
|
27 |
+
|
28 |
+
inp = result.replace('\n','')
|
29 |
+
summary = summarizer(inp)
|
30 |
+
return summary
|
31 |
+
|
32 |
+
import gradio as gr
|
33 |
+
|
34 |
+
grad= gr.Interface(fn=summarize, inputs="text", outputs="text")
|
35 |
+
grad.launch()
|