File size: 2,045 Bytes
f7a8c8e
 
 
 
 
 
 
295d67b
 
f7a8c8e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
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
45
46
47
48
import streamlit as st
import os
import langchain
import langchain_huggingface
import huggingface_hub
from langchain_community.document_loaders import YoutubeLoader
from langchain_huggingface import HuggingFaceEndpoint,ChatHuggingFace
os.environ['HUGGINGFACEHUB_API_TOKEN'] = os.getenv("hf_token")
os.environ['HF_TOKEN'] = os.getenv("hf_token")
meta_llm=HuggingFaceEndpoint(repo_id="meta-llama/Llama-3.1-8B-Instruct",
                             provider="nebius",
                             temperature=0.5,max_new_tokens=150,
                             task="conversational")
model=ChatHuggingFace(llm=meta_llm,
                      repo_id="meta-llama/Llama-3.1-8B-Instruct",
                      provider="nebius",
                      temperature=0.5,
                      max_new_tokens=50,
                      task="conversational")
def get_youtube_transcript(url):
    loader = YoutubeLoader.from_youtube_url(url)
    docs = loader.load()
    return docs[0].page_content

# πŸ“ Function to summarize
def summarize_youtube_video(url):
    transcript = get_youtube_transcript(url)
    if len(transcript) > 3000:
        transcript = transcript[:3000]  # Trim to avoid token limit
    prompt = f"Summarize this YouTube video transcript:\n\n{transcript}"
    response = model.invoke(prompt)
    return response.content
st.set_page_config(page_title="YouTube Video Summarizer", layout="centered")
st.title("🎬 YouTube Video Summarizer")
st.write("Paste a YouTube video URL below to get a concise summary using Llama 3.1 🧠")

youtube_url = st.text_input("πŸ“₯ Enter YouTube URL:")
if st.button("Summarize"):
    if youtube_url.strip() == "":
        st.warning("Please enter a valid YouTube video URL.")
    else:
        with st.spinner("Fetching and summarizing..."):
            try:
                summary = summarize_youtube_video(youtube_url)
                st.success("βœ… Summary Generated:")
                st.write(summary)
            except Exception as e:
                st.error(f"Something went wrong: {e}")