Spaces:
Sleeping
Sleeping
Update app.py
Browse files1123345678910111213141591011121318 unmodified lines3233344035363738453940414249434445462 unmodified lines49505158525354555664576658# main.py# app.pyimport streamlit as stimport osfrom 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
# 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_TOKEN# 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 message new_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) 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, hf_token=HF_TOKEN) 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 lines for msg in st.session_state.messages: st.chat_message(msg['role']).write(msg['content'])
# Exit chat button 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]
# Show chat interface if video is readyif st.session_state.ready: chat_interface() chat_interface()app.py+7-15