Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,65 +1,71 @@
|
|
1 |
import streamlit as st
|
2 |
from search_utils import SemanticSearch
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
)
|
|
|
15 |
|
16 |
-
# Custom CSS
|
17 |
-
st.markdown("""
|
18 |
-
<style>
|
19 |
-
div[data-testid="stExpander"] div[role="button"] p {
|
20 |
-
|
21 |
-
|
22 |
-
}
|
23 |
-
a.source-link {
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
}
|
28 |
-
a.source-link:hover {
|
29 |
-
|
30 |
-
|
31 |
-
}
|
32 |
-
</style>
|
33 |
-
""", unsafe_allow_html=True)
|
34 |
|
35 |
-
search_system = init_search_system()
|
36 |
|
37 |
-
# Main UI
|
38 |
-
st.title("π Semantic Search Engine")
|
39 |
-
query = st.text_input("Enter your search query:", placeholder="Search documents...")
|
40 |
|
41 |
-
if query:
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
st.warning("No matching documents found")
|
55 |
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
|
|
|
|
|
63 |
if st.button("Clear Cache"):
|
64 |
st.cache_resource.clear()
|
65 |
-
st.rerun()
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from search_utils import SemanticSearch
|
3 |
|
4 |
+
def main():
|
5 |
+
st.set_page_config(
|
6 |
+
page_title="Semantic Search Engine",
|
7 |
+
page_icon="π",
|
8 |
+
layout="wide"
|
9 |
+
)
|
10 |
|
11 |
+
# Initialize search system first
|
12 |
+
@st.cache_resource
|
13 |
+
def init_search_system():
|
14 |
+
system = SemanticSearch()
|
15 |
+
system.initialize_system()
|
16 |
+
return system
|
17 |
|
18 |
+
# Custom CSS moved outside cached function
|
19 |
+
st.markdown("""
|
20 |
+
<style>
|
21 |
+
div[data-testid="stExpander"] div[role="button"] p {
|
22 |
+
font-size: 1.2rem;
|
23 |
+
font-weight: bold;
|
24 |
+
}
|
25 |
+
a.source-link {
|
26 |
+
color: #1e88e5 !important;
|
27 |
+
text-decoration: none !important;
|
28 |
+
border-bottom: 1px dotted #1e88e5;
|
29 |
+
}
|
30 |
+
a.source-link:hover {
|
31 |
+
opacity: 0.8;
|
32 |
+
border-bottom-style: solid;
|
33 |
+
}
|
34 |
+
</style>
|
35 |
+
""", unsafe_allow_html=True)
|
36 |
|
37 |
+
search_system = init_search_system()
|
38 |
|
39 |
+
# Main UI components
|
40 |
+
st.title("π Semantic Search Engine")
|
41 |
+
query = st.text_input("Enter your search query:", placeholder="Search documents...")
|
42 |
|
43 |
+
if query:
|
44 |
+
with st.spinner("π Searching through documents..."):
|
45 |
+
results = search_system.search(query, 5)
|
46 |
+
|
47 |
+
if not results.empty:
|
48 |
+
st.subheader("Top Results")
|
49 |
+
for _, row in results.iterrows():
|
50 |
+
with st.expander(f"{row['title']} (Similarity: {row['similarity']:.1%})"):
|
51 |
+
st.markdown(f"**Summary**: {row['summary']")
|
52 |
+
st.markdown(f"<a class='source-link' href='{row['source']}' target='_blank'>View Source</a>",
|
53 |
+
unsafe_allow_html=True)
|
54 |
+
else:
|
55 |
+
st.warning("No matching documents found")
|
|
|
56 |
|
57 |
+
# System status sidebar
|
58 |
+
with st.sidebar:
|
59 |
+
st.subheader("System Status")
|
60 |
+
st.metric("Total Documents", f"{search_system.metadata_mgr.total_docs:,}")
|
61 |
+
st.metric("FAISS Shards", len(search_system.index_shards))
|
62 |
+
st.metric("Metadata Shards", len(search_system.metadata_mgr.shard_map))
|
63 |
|
64 |
+
# Sidebar controls outside main query block
|
65 |
+
with st.sidebar:
|
66 |
if st.button("Clear Cache"):
|
67 |
st.cache_resource.clear()
|
68 |
+
st.rerun()
|
69 |
+
|
70 |
+
if __name__ == "__main__":
|
71 |
+
main()
|