Spaces:
Runtime error
Runtime error
Commit ·
5ccc418
1
Parent(s): 6c63dd8
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#Import Libraries and Modules
|
| 2 |
+
from youtube_transcript_api import YouTubeTranscriptApi
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from gradio.mix import Series
|
| 5 |
+
|
| 6 |
+
#Define a function that extracts video transcripts using youtube video URLs.
|
| 7 |
+
def transcript_extracter(link):
|
| 8 |
+
id = link[link.index("=")+1:]
|
| 9 |
+
|
| 10 |
+
transcript = YouTubeTranscriptApi.get_transcript(id)
|
| 11 |
+
script = ""
|
| 12 |
+
|
| 13 |
+
for text in transcript:
|
| 14 |
+
t = text["text"]
|
| 15 |
+
if t != '[Music]':
|
| 16 |
+
script += t + " "
|
| 17 |
+
|
| 18 |
+
return script
|
| 19 |
+
|
| 20 |
+
generate_transcript_function = gr.Interface(transcript_extracter, 'text', 'text')
|
| 21 |
+
summarizer_model = gr.Interface.load("huggingface/sshleifer/distilbart-cnn-12-6") #Load transformers model.
|
| 22 |
+
|
| 23 |
+
Demo_application = Series(generate_transcript_function, summarizer_model,
|
| 24 |
+
inputs = gr.inputs.Textbox(label = "Enter the YouTube URL: "),
|
| 25 |
+
outputs = gr.outputs.Textbox(label = "Youtube Video Summary"),
|
| 26 |
+
examples = ["https://www.youtube.com/watch?v=Cu3R5it4cQs&list", "https://www.youtube.com/watch?v=HB4I2CgkcCo"],
|
| 27 |
+
title = "YouTube Video Summarizer",
|
| 28 |
+
theme = "grass",
|
| 29 |
+
description = "This application uses the sshleifer/distilbart-cnn-12-6 model to Summarize Youtube Videos. Click on one of the examples given below or
|
| 30 |
+
Enter a video URL of your choice!",
|
| 31 |
+
allow_flagging=False)
|
| 32 |
+
|
| 33 |
+
Demo_application.launch()
|