-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_streamlit.py
More file actions
46 lines (28 loc) · 942 Bytes
/
Copy pathmain_streamlit.py
File metadata and controls
46 lines (28 loc) · 942 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import streamlit as st
import pandas as pd
import txtai
@st.cache_resource
def load_data_and_embeddings():
# Load same dataset
df = pd.read_csv("seth-data.csv").dropna()
# IMPORTANT: same sample as build_index.py
sample = df.sample(1000, random_state=1)
titles = sample["title"].values
urls = sample["url"].values
embeddings = txtai.Embeddings({
"path": "sentence-transformers/all-MiniLM-L6-v2"
})
embeddings.load("embeddings_seth.tar.gz")
return titles, urls, embeddings
titles, urls, embeddings = load_data_and_embeddings()
st.title("Seth Blog Search Engine")
query = st.text_input("Enter a search query")
if st.button("Search"):
if query:
results = embeddings.search(query, 5)
for result in results:
idx = result[0]
st.write(f"### {titles[idx]}")
st.write(urls[idx])
else:
st.write("Please enter a query")