Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,13 @@
|
|
| 1 |
-
#
|
| 2 |
import streamlit as st
|
| 3 |
-
import
|
| 4 |
from config import Config
|
| 5 |
from transcript_utils import extract_video_id, fetch_transcript
|
| 6 |
from vector_utils import build_vector_store, get_retriever
|
| 7 |
from qa_pipeline import run_qa
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
|
| 11 |
-
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 12 |
-
|
| 13 |
-
# You can store them in Config if needed
|
| 14 |
-
Config.GOOGLE_API_KEY = GOOGLE_API_KEY
|
| 15 |
-
Config.HF_TOKEN = HF_TOKEN
|
| 16 |
|
| 17 |
st.set_page_config(page_title="YouTube Video Chat-QA", layout="centered")
|
| 18 |
st.title("YouTube Video Chat-QA App")
|
|
@@ -37,16 +32,15 @@ with st.expander("Setup Video", expanded=not st.session_state.ready):
|
|
| 37 |
# Chat interface after video is ready
|
| 38 |
def chat_interface():
|
| 39 |
st.video(f"https://www.youtube.com/watch?v={st.session_state.video_id}")
|
| 40 |
-
|
| 41 |
# Input new message
|
| 42 |
new_q = st.chat_input("Ask a question about this video...")
|
| 43 |
if new_q:
|
| 44 |
st.session_state.messages.append({'role': 'user', 'content': new_q})
|
| 45 |
-
transcript = fetch_transcript(st.session_state.video_id, languages=["en", "hi"]
|
| 46 |
if not transcript:
|
| 47 |
st.session_state.messages.append({'role': 'assistant', 'content': "Transcript not available."})
|
| 48 |
else:
|
| 49 |
-
vector_store = build_vector_store(transcript, None, Config.EMBEDDING_MODEL
|
| 50 |
retriever = get_retriever(vector_store)
|
| 51 |
answer = run_qa(retriever, new_q)
|
| 52 |
st.session_state.messages.append({'role': 'assistant', 'content': answer})
|
|
@@ -55,12 +49,10 @@ def chat_interface():
|
|
| 55 |
for msg in st.session_state.messages:
|
| 56 |
st.chat_message(msg['role']).write(msg['content'])
|
| 57 |
|
| 58 |
-
# Exit chat button
|
| 59 |
if st.button("Exit Chat"):
|
| 60 |
for key in ['ready', 'video_id', 'messages', 'input_url']:
|
| 61 |
if key in st.session_state:
|
| 62 |
del st.session_state[key]
|
| 63 |
|
| 64 |
-
# Show chat interface if video is ready
|
| 65 |
if st.session_state.ready:
|
| 66 |
-
chat_interface()
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
import streamlit as st
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
from config import Config
|
| 5 |
from transcript_utils import extract_video_id, fetch_transcript
|
| 6 |
from vector_utils import build_vector_store, get_retriever
|
| 7 |
from qa_pipeline import run_qa
|
| 8 |
|
| 9 |
+
# Load environment variables
|
| 10 |
+
load_dotenv()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
st.set_page_config(page_title="YouTube Video Chat-QA", layout="centered")
|
| 13 |
st.title("YouTube Video Chat-QA App")
|
|
|
|
| 32 |
# Chat interface after video is ready
|
| 33 |
def chat_interface():
|
| 34 |
st.video(f"https://www.youtube.com/watch?v={st.session_state.video_id}")
|
|
|
|
| 35 |
# Input new message
|
| 36 |
new_q = st.chat_input("Ask a question about this video...")
|
| 37 |
if new_q:
|
| 38 |
st.session_state.messages.append({'role': 'user', 'content': new_q})
|
| 39 |
+
transcript = fetch_transcript(st.session_state.video_id, languages=["en", "hi"])
|
| 40 |
if not transcript:
|
| 41 |
st.session_state.messages.append({'role': 'assistant', 'content': "Transcript not available."})
|
| 42 |
else:
|
| 43 |
+
vector_store = build_vector_store(transcript, None, Config.EMBEDDING_MODEL)
|
| 44 |
retriever = get_retriever(vector_store)
|
| 45 |
answer = run_qa(retriever, new_q)
|
| 46 |
st.session_state.messages.append({'role': 'assistant', 'content': answer})
|
|
|
|
| 49 |
for msg in st.session_state.messages:
|
| 50 |
st.chat_message(msg['role']).write(msg['content'])
|
| 51 |
|
|
|
|
| 52 |
if st.button("Exit Chat"):
|
| 53 |
for key in ['ready', 'video_id', 'messages', 'input_url']:
|
| 54 |
if key in st.session_state:
|
| 55 |
del st.session_state[key]
|
| 56 |
|
|
|
|
| 57 |
if st.session_state.ready:
|
| 58 |
+
chat_interface()
|