-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
62 lines (43 loc) · 2.03 KB
/
app.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import enum
import streamlit as st
from config import BOOKS
from search import PineconeSearchEngine, SearchEngine, EmbeddingType
PINECONE_DEPLOYMENT = True
DATA = {
"NKJV": "https://www.dropbox.com/s/6jng3ci5jntm3je/NKJV_fixed.csv?dl=1",
"NIV": "https://www.dropbox.com/s/4en48g6fnbckxqy/NIV_fixed.csv?dl=1"
} if PINECONE_DEPLOYMENT else {
"NKJV": "https://www.dropbox.com/s/wd3kxh012jfhjya/NKJV_clean.parquet?dl=1",
"NIV": "https://www.dropbox.com/s/78jm8wh4cqhvwwv/NIV_clean.parquet?dl=1",
}
class Translation(enum.Enum):
NIV = "NIV"
NKJV = "NKJV"
@st.cache_resource
def load_pinecone_engine():
# for Pinecone, only `Ada` is available as its free tier only supports
# a single index. Feel free to change this to multi-engine like in app.py
# if you have access to multiple pinecone indices.
return PineconeSearchEngine(DATA, index="ada")
@st.cache_resource
def load_engine():
# search using in-memory parquet files
return SearchEngine(DATA)
st.title("Search the Bible semantically:")
if PINECONE_DEPLOYMENT:
st.caption("Using Pinecone.")
translation = st.radio("**Translations:**", [trans.value for trans in Translation])
emb_space = st.radio("**Embedding Space:**", [
emb.name for emb in EmbeddingType if emb == EmbeddingType.Ada
] if PINECONE_DEPLOYMENT else [emb.name for emb in EmbeddingType])
query = st.text_input("**Search:**", placeholder="What is the meaning of life?")
if query:
engine = load_pinecone_engine() if PINECONE_DEPLOYMENT else load_engine()
with st.spinner(f'Searching verses in {translation} with {emb_space}...'):
top_results = engine.search(query, translation=translation, emb_type=EmbeddingType[emb_space])
if top_results:
st.subheader("Results:")
for result in top_results:
with st.expander(f"{BOOKS[result.book]} {result.chapter}:{result.verse}", expanded=True):
st.write(f"**{result.text}**")
st.caption("You can find the codebase at this Github [repo](https://github.com/ashrielbrian/bible_semsearch).")