Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
from youtube_transcript_api import YouTubeTranscriptApi
|
| 4 |
+
import re
|
| 5 |
+
|
| 6 |
+
# Initialize summarization pipeline
|
| 7 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 8 |
+
|
| 9 |
+
# Helper function to extract text from a YouTube video transcript
|
| 10 |
+
def get_youtube_transcript(url):
|
| 11 |
+
try:
|
| 12 |
+
video_id = re.search(r"v=([a-zA-Z0-9_-]+)", url).group(1)
|
| 13 |
+
transcript = YouTubeTranscriptApi.get_transcript(video_id)
|
| 14 |
+
return " ".join([entry['text'] for entry in transcript])
|
| 15 |
+
except Exception as e:
|
| 16 |
+
st.error(f"Error fetching transcript: {e}")
|
| 17 |
+
return ""
|
| 18 |
+
|
| 19 |
+
# Streamlit app layout
|
| 20 |
+
st.set_page_config(page_title="Summarify", layout="wide")
|
| 21 |
+
st.sidebar.image("path_to_your_logo.png", use_column_width=True)
|
| 22 |
+
st.sidebar.title("Summarify")
|
| 23 |
+
st.sidebar.subheader("Options")
|
| 24 |
+
option = st.sidebar.selectbox("Select an option:", ["YouTube Link Summarization"])
|
| 25 |
+
|
| 26 |
+
if option == "YouTube Link Summarization":
|
| 27 |
+
st.title("YouTube Link Summarization")
|
| 28 |
+
url = st.text_input("Enter the YouTube video URL:")
|
| 29 |
+
if url:
|
| 30 |
+
with st.spinner("Fetching transcript..."):
|
| 31 |
+
transcript = get_youtube_transcript(url)
|
| 32 |
+
if transcript:
|
| 33 |
+
st.write("**Transcript:**")
|
| 34 |
+
st.write(transcript)
|
| 35 |
+
if st.button("Summarize"):
|
| 36 |
+
with st.spinner("Summarizing..."):
|
| 37 |
+
summary = summarizer(transcript, max_length=500, min_length=100, do_sample=False)
|
| 38 |
+
st.write("**Summary:**")
|
| 39 |
+
st.write(summary[0]['summary_text'])
|