import streamlit as st import time # ============================== # PAGE CONFIG # ============================== st.set_page_config( page_title="Voice of the Sign", page_icon="🦅", layout="wide", initial_sidebar_state="expanded" ) # ============================== # LOAD BACKEND # ============================== backend_loaded = False try: from app import get_rag_chain, search_archives backend_loaded = True except Exception as e: st.error(f"❌ Backend failed to load:\n\n{e}") # ============================== # MESSAGEHUB LINK BUILDER # ============================== def messagehub_link(filename: str): """ Example: 62-0909E In His Presence.pdf → https://www.messagehub.info/en/read.do?ref_num=62-0909E """ if not filename: return "#" name = filename.replace(".pdf", "").replace(".PDF", "").strip() code = name.split()[0] # first token is sermon code return f"https://www.messagehub.info/en/read.do?ref_num={code}" # ============================== # STYLING # ============================== st.markdown(""" """, unsafe_allow_html=True) # ============================== # SESSION STATE # ============================== if "chat_history" not in st.session_state: st.session_state.chat_history = [] # ============================== # SIDEBAR # ============================== with st.sidebar: st.title("🦅 Controls") mode = st.radio("Mode", ["🗣️ Chat with The Message", "🔍 Search The Word"], index=0, label_visibility="collapsed") st.divider() if st.button("🗑️ Clear Screen", use_container_width=True): st.session_state.chat_history = [] st.rerun() # ============================== # HEADER # ============================== col1, col2 = st.columns([1, 14]) with col1: st.markdown("# 🦅") with col2: st.markdown("# The 7th Handle" if mode.startswith("🗣️") else "# The Table") st.divider() if not backend_loaded: st.stop() # ============================== # LOAD RAG SYSTEM # ============================== @st.cache_resource(show_spinner=False) def load_chain(): return get_rag_chain() # ========================================================= # CHAT MODE # ========================================================= if mode.startswith("🗣️"): # --- Render chat history --- for msg in st.session_state.chat_history: with st.chat_message(msg["role"], avatar="👤" if msg["role"] == "user" else "🦅"): st.markdown(msg["content"], unsafe_allow_html=False) if msg.get("sources"): with st.expander("📚 References"): for doc in msg["sources"]: src = doc.metadata.get("source", "") para = doc.metadata.get("paragraph", "") link = messagehub_link(src) st.markdown(f"🔗 [{src} (Para {para})]({link})") # --- CHAT DESCRIPTION --- st.markdown( """