| import streamlit as st |
| from rag_chain import get_rag_chain |
|
|
| st.set_page_config(page_title="Cricket Chat", page_icon="๐") |
| st.title("YouTube Video Chatbot") |
|
|
| video_id = st.text_input("Enter YouTube video ID (e.g. Gfr50f6ZBvo)") |
|
|
| if video_id and st.session_state.get("current_video") != video_id: |
| with st.spinner("Processing transcript..."): |
| try: |
| st.session_state.chain = get_rag_chain(video_id) |
| st.session_state.current_video = video_id |
| st.session_state.messages = [] |
| st.success("Ready! Ask away.") |
| except ValueError as e: |
| st.error(str(e)) |
| st.stop() |
|
|
| if "messages" not in st.session_state: |
| st.session_state.messages = [] |
|
|
| for msg in st.session_state.messages: |
| with st.chat_message(msg["role"]): |
| st.markdown(msg["content"]) |
|
|
| if "chain" in st.session_state: |
| if prompt := st.chat_input("Ask about the video..."): |
| st.session_state.messages.append({"role": "user", "content": prompt}) |
| with st.chat_message("user"): |
| st.markdown(prompt) |
|
|
| with st.chat_message("assistant"): |
| with st.spinner("Thinking..."): |
| response = st.session_state.chain.invoke(prompt) |
| st.markdown(response) |
| st.session_state.messages.append({"role": "assistant", "content": response}) |