Spaces:
Sleeping
Sleeping
DeepSoft-Tech
commited on
Commit
•
dcb704e
1
Parent(s):
3a80f0a
Update app.py
Browse files
app.py
CHANGED
@@ -13,53 +13,53 @@ st.set_page_config(page_title="Search Engine", layout="wide")
|
|
13 |
|
14 |
# Set up the Streamlit app title and search bar
|
15 |
st.title("Search Engine")
|
16 |
-
|
17 |
-
with st.form("my_form"
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
# Every form must have a submit button.
|
26 |
-
submitted = st.form_submit_button("Connect to My Search Engine")
|
27 |
-
if submitted:
|
28 |
-
# if st.button("Connect to Search Engine Database", type="primary"):
|
29 |
-
# index_name = st.text_input("Enter a database name:", "")
|
30 |
-
# key = st.text_input("Enter a key:", "")
|
31 |
-
# namespace = st.text_input("Enter a table name:", "")
|
32 |
-
# # initialize connection to pinecone (get API key at app.pinecone.io)
|
33 |
-
|
34 |
-
api_key = os.environ.get('PINECONE_API_KEY') or key
|
35 |
-
|
36 |
-
# configure client
|
37 |
-
pc = Pinecone(api_key=api_key)
|
38 |
-
|
39 |
-
from pinecone import ServerlessSpec
|
40 |
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
st.write('Successfully connected to your Search Engine DB!')
|
50 |
-
st.write('Start searching...')
|
51 |
-
|
52 |
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
-
# If the user has entered a search query, search the Pinecone index with the query
|
56 |
-
if query:
|
57 |
-
# Upsert the embeddings for the query into the Pinecone index
|
58 |
-
query_embeddings = model.encode(query).tolist()
|
59 |
-
# now query
|
60 |
-
xc = index.query(vector=query_embeddings, top_k=10, namespace=namespace, include_metadata=True)
|
61 |
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
# Set up the Streamlit app title and search bar
|
15 |
st.title("Search Engine")
|
16 |
+
with st.sidebar:
|
17 |
+
with st.form("my_form":
|
18 |
+
st.write("Login to Search Engine")
|
19 |
+
index_name = st.text_input("Enter a database name:", "")
|
20 |
+
key = st.text_input("Enter a key:", "")
|
21 |
+
namespace = st.text_input("Enter a table name:", "")
|
22 |
+
# slider_val = st.slider("Form slider")
|
23 |
+
# checkbox_val = st.checkbox("Form checkbox")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
+
# Every form must have a submit button.
|
26 |
+
submitted = st.form_submit_button("Connect to My Search Engine")
|
27 |
+
if submitted:
|
28 |
+
# if st.button("Connect to Search Engine Database", type="primary"):
|
29 |
+
# index_name = st.text_input("Enter a database name:", "")
|
30 |
+
# key = st.text_input("Enter a key:", "")
|
31 |
+
# namespace = st.text_input("Enter a table name:", "")
|
32 |
+
# # initialize connection to pinecone (get API key at app.pinecone.io)
|
|
|
|
|
|
|
33 |
|
34 |
+
api_key = os.environ.get('PINECONE_API_KEY') or key
|
35 |
+
|
36 |
+
# configure client
|
37 |
+
pc = Pinecone(api_key=api_key)
|
38 |
+
|
39 |
+
from pinecone import ServerlessSpec
|
40 |
+
|
41 |
+
cloud = os.environ.get('PINECONE_CLOUD') or 'aws'
|
42 |
+
region = os.environ.get('PINECONE_REGION') or 'us-east-1'
|
43 |
+
|
44 |
+
spec = ServerlessSpec(cloud=cloud, region=region)
|
45 |
+
|
46 |
+
|
47 |
+
# connect to index
|
48 |
+
index = pc.Index(index_name)
|
49 |
+
st.write('Successfully connected to your Search Engine DB!')
|
50 |
+
st.write('Start searching...')
|
51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
+
query = st.text_input("Enter a search query:", "")
|
54 |
+
|
55 |
+
# If the user has entered a search query, search the Pinecone index with the query
|
56 |
+
if query:
|
57 |
+
# Upsert the embeddings for the query into the Pinecone index
|
58 |
+
query_embeddings = model.encode(query).tolist()
|
59 |
+
# now query
|
60 |
+
xc = index.query(vector=query_embeddings, top_k=10, namespace=namespace, include_metadata=True)
|
61 |
+
|
62 |
+
# Display the search results
|
63 |
+
st.write(f"Search results for '{query}':")
|
64 |
+
for result in xc['matches']:
|
65 |
+
st.write(f"{round(result['score'], 2)}: {result['metadata']['meta_text']}")
|