semantic-search / app.py
Testys's picture
Update app.py
d134e08
raw
history blame
1.93 kB
# 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))