Pasham123 commited on
Commit
8a46f61
·
verified ·
1 Parent(s): 592e9cc

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +47 -39
src/streamlit_app.py CHANGED
@@ -1,40 +1,48 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
  import streamlit as st
5
-
6
- """
7
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import os
3
+ import langchain
4
+ import langchain_huggingface
5
+ import huggingface_hub
6
+ from langchain_community.document_loaders import YoutubeLoader
7
+ from langchain_huggingface import HuggingFaceEndpoint,ChatHuggingFace
8
+ os.environ['HUGGINGFACEHUB_API_TOKEN'] = os.getenv("hf")
9
+ os.environ['HF_TOKEN'] = os.getenv("hf")
10
+ meta_llm=HuggingFaceEndpoint(repo_id="meta-llama/Llama-3.1-8B-Instruct",
11
+ provider="nebius",
12
+ temperature=0.5,max_new_tokens=150,
13
+ task="conversational")
14
+ model=ChatHuggingFace(llm=meta_llm,
15
+ repo_id="meta-llama/Llama-3.1-8B-Instruct",
16
+ provider="nebius",
17
+ temperature=0.5,
18
+ max_new_tokens=50,
19
+ task="conversational")
20
+ def get_youtube_transcript(url):
21
+ loader = YoutubeLoader.from_youtube_url(url)
22
+ docs = loader.load()
23
+ return docs[0].page_content
24
+
25
+ # 📝 Function to summarize
26
+ def summarize_youtube_video(url):
27
+ transcript = get_youtube_transcript(url)
28
+ if len(transcript) > 3000:
29
+ transcript = transcript[:3000] # Trim to avoid token limit
30
+ prompt = f"Summarize this YouTube video transcript:\n\n{transcript}"
31
+ response = model.invoke(prompt)
32
+ return response.content
33
+ st.set_page_config(page_title="YouTube Video Summarizer", layout="centered")
34
+ st.title("📻 YouTube Video Summarizer")
35
+ st.write("Paste a YouTube video URL below to get a concise summary using Llama 3.1 🧠")
36
+
37
+ youtube_url = st.text_input("📥 Enter YouTube URL:")
38
+ if st.button("Summarize"):
39
+ if youtube_url.strip() == "":
40
+ st.warning("Please enter a valid YouTube video URL.")
41
+ else:
42
+ with st.spinner("Fetching and summarizing..."):
43
+ try:
44
+ summary = summarize_youtube_video(youtube_url)
45
+ st.success("✅ Summary Generated:")
46
+ st.write(summary)
47
+ except Exception as e:
48
+ st.error(f"Something went wrong: {e}")