File size: 1,346 Bytes
56812fd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | 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}) |