File size: 2,284 Bytes
e812ccd
 
471185d
e812ccd
c45b00b
54174be
e812ccd
 
 
 
 
471185d
 
 
 
 
 
 
 
e812ccd
 
 
471185d
 
e812ccd
 
471185d
e812ccd
 
471185d
e812ccd
471185d
e812ccd
c75f2fc
 
 
 
 
 
c1ea157
eeef8f5
c75f2fc
 
54174be
e812ccd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""Main Streamlit application for LegisQA"""

import logging
import streamlit as st
from legisqa_local.config.settings import STREAMLIT_CONFIG, setup_environment, inspect_chromadb
from legisqa_local.core.vectorstore import initialize_vectorstore
from legisqa_local.components.sidebar import render_sidebar
from legisqa_local.tabs.rag_tab import RAGTab
from legisqa_local.tabs.rag_sbs_tab import RAGSideBySideTab
from legisqa_local.tabs.guide_tab import GuideTab

# Configure logging (should be done once at application startup)
logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
    force=True  # Force reconfiguration if already configured
)
logger = logging.getLogger(__name__)


def main():
    """Main application function"""
    logger.info("πŸš€ Starting LegisQA application...")
    
    # Configure Streamlit
    st.set_page_config(**STREAMLIT_CONFIG)
    logger.info("βœ… Streamlit configuration complete")
    
    # Setup environment
    logger.info("πŸ”§ Setting up environment...")
    setup_environment()
    logger.info("βœ… Environment setup complete")
    
    # Setup ChromaDB (download if needed) - run once per session
    if "chromadb_inspected" not in st.session_state:
        logger.info("πŸ’Ύ Inspecting ChromaDB...")
        inspect_chromadb()
        logger.info("βœ… ChromaDB inspection complete")
        st.session_state.chromadb_inspected = True
    
    # Initialize vectorstore (load once and cache in session state)
    if "vectorstore" not in st.session_state:
        initialize_vectorstore()
    
    # Main content
    st.title(":classical_building: LegisQA :classical_building:")
    st.header("Query Congressional Bills")

    # Sidebar
    with st.sidebar:
        render_sidebar()

    # Create tab instances
    rag_tab = RAGTab()
    rag_sbs_tab = RAGSideBySideTab()
    guide_tab = GuideTab()

    # Create tabs
    query_rag_tab, query_rag_sbs_tab, guide_tab_ui = st.tabs([
        rag_tab.name,
        rag_sbs_tab.name,
        guide_tab.name,
    ])

    # Render tab content
    with query_rag_tab:
        rag_tab.render()

    with query_rag_sbs_tab:
        rag_sbs_tab.render()

    with guide_tab_ui:
        guide_tab.render()


if __name__ == "__main__":
    main()