Spaces:
Sleeping
Sleeping
| # app.py | |
| import streamlit as st | |
| from search_utils import SemanticSearch | |
| 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)) |