File size: 2,747 Bytes
cfd73e5
 
 
 
91c48e2
a56f268
1a74017
f3c85fe
 
1a74017
bb7e478
 
cfd73e5
c7a6370
cfd73e5
c7a6370
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cfd73e5
c7a6370
 
cfd73e5
c7a6370
a56f268
c7a6370
 
 
 
 
 
 
 
 
 
 
 
a56f268
c7a6370
a56f268
 
032608d
87faf98
032608d
 
a56f268
032608d
a56f268
c7a6370
 
a56f268
 
 
032608d
c7a6370
 
 
 
a56f268
c7a6370
 
032608d
c7a6370
 
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import os
import streamlit as st
from langchain.prompts import ChatPromptTemplate, SystemMessagePromptTemplate, HumanMessagePromptTemplate
from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
from youtube_transcript_api import YouTubeTranscriptApi
from langchain_community.document_loaders import YoutubeLoader
from langchain_google_genai import GoogleGenerativeAI,ChatGoogleGenerativeAI
from youtube_transcript_api._errors import TranscriptsDisabled


gemini_token = os.environ.get("gemini")
os.environ["GOOGLE_API_KEY"] = gemini_token

st.set_page_config(page_title="🎬 Tube2Insight", page_icon="πŸŽ₯", layout="wide")

st.markdown("""
    <style>
        .stApp { background-color: #f7f9fc; }
        .video-card {
            background-color: #ffffff;
            border: 2px solid #e0e0e0;
            padding: 20px;
            border-radius: 15px;
            text-align: center;
            box-shadow: 2px 2px 10px #ddd;
        }
        .video-card:hover {
            border-color: #FF4B4B;
            box-shadow: 3px 3px 12px #bbb;
        }
    </style>
""", unsafe_allow_html=True)

st.markdown("<h1 style='text-align: center; color: #FF4B4B;'>🎬 Tube2Insight</h1>", unsafe_allow_html=True)
st.markdown("### Paste a YouTube link below to get an instant summary πŸ‘‡")

video_url = st.text_input("πŸ“Ί YouTube Video URL")

if st.button("πŸ” Summarize"):
    if not video_url:
        st.warning("Please provide a video link.")
    else:
        with st.spinner("πŸ“„ Fetching transcript..."):
            try:
                docs = YoutubeLoader.from_youtube_url(video_url).load()
                transcript = docs[0].page_content
                st.success("βœ… Transcript loaded!")
            except Exception as e:
                st.error(f"Error loading video: {e}")
                st.stop()

        with st.expander("πŸ“„ View Transcript"):
            st.write(transcript)

        llm = ChatGoogleGenerativeAI(
            model="gemini-2.0-flash",
            temperature=0.5,
            max_output_tokens=512
        )

        prompt = ChatPromptTemplate.from_messages([
            SystemMessagePromptTemplate.from_template("You are a helpful assistant summarizing YouTube transcripts."),
            HumanMessagePromptTemplate.from_template("{transcript}")
        ])
        messages = prompt.format_messages(transcript=transcript)

        with st.spinner("🧠 Summarizing with Gemini 2.0 Flash..."):
            response = llm.invoke(messages)

        st.markdown("### πŸ“Œ Summary")
        st.success(response.content)

st.markdown("---")
st.markdown(
    "<p style='text-align: center; color: gray;'>πŸš€ Built with LangChain + Gemini + Streamlit </p>",
    unsafe_allow_html=True
)