Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import transformers
|
| 3 |
+
import youtube_transcript_api
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
from youtube_transcript_api import YouTubeTranscriptApi
|
| 6 |
+
from datasets import Dataset
|
| 7 |
+
|
| 8 |
+
summarizer = pipeline("summarization",model="facebook/bart-large-cnn")
|
| 9 |
+
|
| 10 |
+
def greet(link):
|
| 11 |
+
try:
|
| 12 |
+
unique_id = link.split("=")[-1]
|
| 13 |
+
sub = YouTubeTranscriptApi.get_transcript(unique_id)
|
| 14 |
+
subtitle = " ".join([w['text'] for w in sub])
|
| 15 |
+
summary = summarizer(subtitle, max_length=180, min_length=30, do_sample=False)
|
| 16 |
+
return summary[0]['summary_text']
|
| 17 |
+
except:
|
| 18 |
+
return 'Invalid URL'
|
| 19 |
+
|
| 20 |
+
demo=gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 21 |
+
|
| 22 |
+
if __name__ == "__main__":
|
| 23 |
+
demo.launch()
|