Spaces:
Runtime error
Runtime error
aa
Browse files
app.py
CHANGED
@@ -1,44 +1,43 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
-
import
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
def
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import BartForConditionalGeneration, BartTokenizer
|
3 |
+
from youtube_transcript_api import YouTubeTranscriptApi
|
4 |
+
|
5 |
+
# Load BART model and tokenizer
|
6 |
+
model_name = 'facebook/bart-large-cnn'
|
7 |
+
tokenizer = BartTokenizer.from_pretrained(model_name)
|
8 |
+
model = BartForConditionalGeneration.from_pretrained(model_name)
|
9 |
+
|
10 |
+
def get_transcript(url):
|
11 |
+
try:
|
12 |
+
video_id = url.split('=')[1]
|
13 |
+
transcript_list = YouTubeTranscriptApi.get_transcript(video_id)
|
14 |
+
transcript_text = ""
|
15 |
+
for item in transcript_list:
|
16 |
+
transcript_text += item['text'] + "\n"
|
17 |
+
return transcript_text
|
18 |
+
except Exception as e:
|
19 |
+
return "Error fetching transcript: " + str(e)
|
20 |
+
|
21 |
+
def summarize_transcript(transcript):
|
22 |
+
input_ids = tokenizer.encode("summarize: " + transcript, return_tensors="pt", max_length=1024, truncation=True)
|
23 |
+
summary_ids = model.generate(input_ids, num_beams=4, min_length=30, max_length=200, early_stopping=True)
|
24 |
+
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
25 |
+
return summary
|
26 |
+
|
27 |
+
def summarize_video_url(video_url):
|
28 |
+
transcript = get_transcript(video_url)
|
29 |
+
if not transcript:
|
30 |
+
return "Error fetching transcript."
|
31 |
+
else:
|
32 |
+
summary = summarize_transcript(transcript)
|
33 |
+
return summary
|
34 |
+
|
35 |
+
inputs = gr.inputs.Textbox(lines=5, label="Enter YouTube Video URL")
|
36 |
+
output = gr.outputs.Textbox(label="Summary")
|
37 |
+
|
38 |
+
title = "YouTube Video Transcription Summarizer"
|
39 |
+
description = "Enter a YouTube Video URL to get a summary of its transcript."
|
40 |
+
|
41 |
+
iface = gr.Interface(fn=summarize_video_url, inputs=inputs, outputs=output, title=title, description=description)
|
42 |
+
|
43 |
+
iface.launch(share=True)
|
|