Spaces:
Sleeping
Sleeping
Create app.py
Browse filesfirst iteration
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pytube
|
3 |
+
from transformers import pipeline
|
4 |
+
|
5 |
+
# Initialize pipelines
|
6 |
+
asr = pipeline("automatic-speech-recognition", model="openai/whisper-base", chunk_length_s=30)
|
7 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
8 |
+
|
9 |
+
def summarize_youtube(url):
|
10 |
+
# Download audio
|
11 |
+
yt = pytube.YouTube(url)
|
12 |
+
stream = yt.streams.filter(only_audio=True).first()
|
13 |
+
stream.download(filename="audio.mp3")
|
14 |
+
|
15 |
+
# Transcribe
|
16 |
+
result = asr("audio.mp3")
|
17 |
+
transcript = result["text"]
|
18 |
+
|
19 |
+
# Summarize
|
20 |
+
summary = summarizer(transcript, max_length=150, min_length=50, do_sample=False)[0]["summary_text"]
|
21 |
+
|
22 |
+
# Embed video
|
23 |
+
v_id = url.split("v=")[-1]
|
24 |
+
embed_html = f'<iframe width="560" height="315" src="https://www.youtube.com/embed/{v_id}" frameborder="0" allowfullscreen></iframe>'
|
25 |
+
|
26 |
+
return embed_html, transcript, summary
|
27 |
+
|
28 |
+
# Build Gradio app
|
29 |
+
with gr.Blocks() as demo:
|
30 |
+
gr.Markdown("## 🎓 Multi‑lingual YouTube Summarizer (Hindi / Hinglish / English)")
|
31 |
+
url_input = gr.Textbox(label="YouTube URL")
|
32 |
+
vid, txt, summ = gr.HTML(), gr.Textbox(label="Transcript"), gr.Textbox(label="Summary")
|
33 |
+
btn = gr.Button("Summarize")
|
34 |
+
btn.click(summarize_youtube, inputs=url_input, outputs=[vid, txt, summ])
|
35 |
+
|
36 |
+
demo.launch()
|