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