Spaces:
				
			
			
	
			
			
					
		Running
		
	
	
	
			
			
	
	
	
	
		
		
					
		Running
		
	File size: 2,300 Bytes
			
			| 6129cb8 7f849e0 6129cb8 7f849e0 6129cb8 7f849e0 6129cb8 7f849e0 2b6cdbb 7f849e0 6129cb8 7f849e0 d1f3bf3 7f849e0 2b6cdbb 7f849e0 2b6cdbb 7f849e0 2b6cdbb 7f849e0 | 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 | import streamlit as st
from search_utils import SemanticSearch
def main():
    st.set_page_config(
        page_title="Semantic Search Engine",
        page_icon="π",
        layout="wide"
    )
    # Initialize search system first
    @st.cache_resource
    def init_search_system():
        system = SemanticSearch()
        system.initialize_system()
        return system
    # Custom CSS moved outside cached function
    st.markdown("""
    <style>
    div[data-testid="stExpander"] div[role="button"] p {
        font-size: 1.2rem;
        font-weight: bold;
    }
    a.source-link {
        color: #1e88e5 !important;
        text-decoration: none !important;
        border-bottom: 1px dotted #1e88e5;
    }
    a.source-link:hover {
        opacity: 0.8;
        border-bottom-style: solid;
    }
    </style>
    """, unsafe_allow_html=True)
    search_system = init_search_system()
    # Main UI components
    st.title("π Semantic Search Engine")
    query = st.text_input("Enter your search query:", placeholder="Search documents...")
    if query:
        with st.spinner("π Searching through documents..."):
            results = search_system.search(query, 5)
            
            if not results.empty:
                st.subheader("Top Results")
                for _, row in results.iterrows():
                    with st.expander(f"{row['title']} (Similarity: {row['similarity']:.1%})"):
                        st.markdown(f"**Summary**: {row['summary']}")
                        st.markdown(f"<a class='source-link' href='{row['source']}' target='_blank'>View Source</a>", 
                                  unsafe_allow_html=True)
            else:
                st.warning("No matching documents found")
        # System status sidebar
        with st.sidebar:
            st.subheader("System Status")
            st.metric("Total Documents", f"{search_system.metadata_mgr.total_docs:,}")
            st.metric("FAISS Shards", len(search_system.index_shards))
            st.metric("Metadata Shards", len(search_system.metadata_mgr.shard_map))
    # Sidebar controls outside main query block
    with st.sidebar:
        if st.button("Clear Cache"):
            st.cache_resource.clear()
            st.rerun()
if __name__ == "__main__":
    main() | 
