File size: 1,969 Bytes
6129cb8
 
 
 
 
d134e08
6129cb8
 
 
d134e08
 
 
 
 
6129cb8
2b6cdbb
d134e08
 
2b6cdbb
 
 
 
d134e08
2b6cdbb
d134e08
2b6cdbb
d134e08
 
2b6cdbb
 
d134e08
 
 
6129cb8
2b6cdbb
 
 
d134e08
2b6cdbb
6129cb8
 
2b6cdbb
d134e08
6129cb8
2b6cdbb
 
 
 
 
 
 
 
 
 
 
 
d134e08
2b6cdbb
 
 
 
 
 
 
 
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
import streamlit as st
from search_utils import SemanticSearch

@st.cache_resource
def init_search_system():
    search_system = SemanticSearch()
    search_system.initialize_system()
    return search_system

st.set_page_config(
    page_title="Semantic Search Engine",
    page_icon="πŸ”",
    layout="wide"
)

# Custom CSS for better presentation
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
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)
        
        # Display results
        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))

        if st.button("Clear Cache"):
            st.cache_resource.clear()
            st.rerun()