Spaces:
Sleeping
Sleeping
Update app.py
Browse files12345678910111213141516171818 unmodified lines373839404142434445464748495051522 unmodified lines555657585960616263646566# main.pyimport streamlit as stimport osfrom config import Configfrom transcript_utils import extract_video_id, fetch_transcriptfrom vector_utils import build_vector_store, get_retrieverfrom qa_pipeline import run_qa# Access secrets from Hugging Face Spaces environment variablesGOOGLE_API_KEY = os.environ.get("GOOGLE_API_KEY")HF_TOKEN = os.environ.get("HF_TOKEN")# You can store them in Config if neededConfig.GOOGLE_API_KEY = GOOGLE_API_KEYConfig.HF_TOKEN = HF_TOKENst.set_page_config(page_title="YouTube Video Chat-QA", layout="centered")st.title("YouTube Video Chat-QA App")18 unmodified lines# Chat interface after video is readydef chat_interface():st.video(f"https://www.youtube.com/watch?v={st.session_state.video_id}")# Input new messagenew_q = st.chat_input("Ask a question about this video...")if new_q:st.session_state.messages.append({'role': 'user', 'content': new_q})transcript = fetch_transcript(st.session_state.video_id, languages=["en", "hi"], api_key=GOOGLE_API_KEY)if not transcript:st.session_state.messages.append({'role': 'assistant', 'content': "Transcript not available."})else:vector_store = build_vector_store(transcript, None, Config.EMBEDDING_MODEL, hf_token=HF_TOKEN)retriever = get_retriever(vector_store)answer = run_qa(retriever, new_q)st.session_state.messages.append({'role': 'assistant', 'content': answer})2 unmodified linesfor msg in st.session_state.messages:st.chat_message(msg['role']).write(msg['content'])# Exit chat buttonif st.button("Exit Chat"):for key in ['ready', 'video_id', 'messages', 'input_url']:if key in st.session_state:del st.session_state[key]# Show chat interface if video is readyif st.session_state.ready:chat_interface()1234567891011121318 unmodified lines3233343536373839404142434445462 unmodified lines49505152535455565758# app.pyimport streamlit as stfrom dotenv import load_dotenvfrom config import Configfrom transcript_utils import extract_video_id, fetch_transcriptfrom vector_utils import build_vector_store, get_retrieverfrom qa_pipeline import run_qa# Load environment variablesload_dotenv()st.set_page_config(page_title="YouTube Video Chat-QA", layout="centered")st.title("YouTube Video Chat-QA App")18 unmodified lines# Chat interface after video is readydef chat_interface():st.video(f"https://www.youtube.com/watch?v={st.session_state.video_id}")# Input new messagenew_q = st.chat_input("Ask a question about this video...")if new_q:st.session_state.messages.append({'role': 'user', 'content': new_q})transcript = fetch_transcript(st.session_state.video_id, languages=["en", "hi"])if not transcript:st.session_state.messages.append({'role': 'assistant', 'content': "Transcript not available."})else:vector_store = build_vector_store(transcript, None, Config.EMBEDDING_MODEL)retriever = get_retriever(vector_store)answer = run_qa(retriever, new_q)st.session_state.messages.append({'role': 'assistant', 'content': answer})2 unmodified linesfor msg in st.session_state.messages:st.chat_message(msg['role']).write(msg['content'])if st.button("Exit Chat"):for key in ['ready', 'video_id', 'messages', 'input_url']:if key in st.session_state:del st.session_state[key]if st.session_state.ready:chat_interface()
app.py+7-15