File size: 1,926 Bytes
d134e08
6129cb8
 
 
 
 
d134e08
6129cb8
 
 
d134e08
 
 
 
 
 
 
 
 
6129cb8
d134e08
6129cb8
d134e08
 
 
 
 
 
 
 
 
 
 
 
 
 
6129cb8
d134e08
 
 
6129cb8
 
 
d134e08
6129cb8
d134e08
 
 
6129cb8
d134e08
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# app.py
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

def format_source(url):
    """Convert URL to clickable link"""
    return f'<a href="{url}" target="_blank" style="text-decoration: none;">🌐 Source</a>'

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

search_system = init_search_system()

# Custom CSS for better link display
st.markdown("""
<style>
a.source-link {
    color: #1a73e8 !important;
    text-decoration: none !important;
    transition: opacity 0.2s;
}
a.source-link:hover {
    opacity: 0.7;
    text-decoration: none !important;
}
</style>
""", unsafe_allow_html=True)

# Search interface
st.title("πŸ” Semantic Search Engine")
query = st.text_input("Search knowledge base:", placeholder="Enter your question...")

if query:
    with st.spinner("Searching through documents..."):
        results = search_system.search(query, 5)
        
        # Format sources as links
        results['source'] = results['source'].apply(
            lambda x: f'<a class="source-link" href="{x}" target="_blank">🌐 View Source</a>'
        )
        
        # Display results with HTML
        st.markdown("### Search Results")
        for _, row in results.iterrows():
            with st.container(border=True):
                st.markdown(f"**{row['title']}**")
                st.markdown(row['summary'])
                st.markdown(row['source'], unsafe_allow_html=True)
                st.progress(float(row['similarity']))
                
    # Sidebar information
    with st.sidebar:
        st.markdown("### System Status")
        st.metric("Loaded Documents", f"{len(search_system.metadata_mgr.shard_map):,}")
        st.metric("Index Shards", len(search_system.index_shards))