Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from search_utils import SemanticSearch
|
3 |
+
|
4 |
+
@st.cache_resource
|
5 |
+
def init_search_system():
|
6 |
+
search_system = SemanticSearch(shard_dir="compressed_shards")
|
7 |
+
search_system.initialize_system()
|
8 |
+
return search_system
|
9 |
+
|
10 |
+
st.set_page_config(page_title="Research Paper Semantic Search with FAISS", layout="wide")
|
11 |
+
search_system = init_search_system()
|
12 |
+
|
13 |
+
st.title("🔍 Research Paper Semantic Search")
|
14 |
+
col1, col2 = st.columns([3, 1])
|
15 |
+
|
16 |
+
with col1:
|
17 |
+
query = st.text_input("Search query:", placeholder="Enter your search...")
|
18 |
+
|
19 |
+
with col2:
|
20 |
+
top_k = st.slider("Results count:", 1, 20, 5)
|
21 |
+
threshold = st.slider("Similarity threshold:", 0.0, 1.0, 0.6)
|
22 |
+
|
23 |
+
if query:
|
24 |
+
with st.spinner("Searching through documents..."):
|
25 |
+
base_results = search_system.search(query, top_k)
|
26 |
+
threshold_results = search_system.search_with_threshold(query, top_k, threshold)
|
27 |
+
|
28 |
+
st.subheader("Top Matches")
|
29 |
+
st.dataframe(
|
30 |
+
base_results.style.format({'similarity': "{:.2%}"}),
|
31 |
+
use_container_width=True,
|
32 |
+
hide_index=True
|
33 |
+
)
|
34 |
+
|
35 |
+
st.subheader(f"Filtered (>{threshold:.0%} similarity)")
|
36 |
+
if not threshold_results.empty:
|
37 |
+
st.dataframe(
|
38 |
+
threshold_results.style.format({'similarity': "{:.2%}"}),
|
39 |
+
use_container_width=True,
|
40 |
+
hide_index=True
|
41 |
+
)
|
42 |
+
else:
|
43 |
+
st.warning("No results meet the similarity threshold")
|
44 |
+
|
45 |
+
with st.sidebar:
|
46 |
+
st.header("System Info")
|
47 |
+
st.markdown(f"""
|
48 |
+
- **Loaded Shards:** {len(search_system.index_shards)}
|
49 |
+
- **Embedding Model:** `all-MiniLM-L6-v2`
|
50 |
+
""")
|
51 |
+
|
52 |
+
if st.button("Clear Cache"):
|
53 |
+
st.cache_resource.clear()
|
54 |
+
st.rerun()
|