Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,35 +18,36 @@ if st.button("Connect to Search Engine Database", type="primary"):
|
|
| 18 |
key = st.text_input("Enter a key:", "")
|
| 19 |
namespace = st.text_input("Enter a table name:", "")
|
| 20 |
# initialize connection to pinecone (get API key at app.pinecone.io)
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
query = st.text_input("Enter a search query:", "")
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
key = st.text_input("Enter a key:", "")
|
| 19 |
namespace = st.text_input("Enter a table name:", "")
|
| 20 |
# initialize connection to pinecone (get API key at app.pinecone.io)
|
| 21 |
+
if key:
|
| 22 |
+
api_key = os.environ.get('PINECONE_API_KEY') or key
|
| 23 |
+
|
| 24 |
+
# configure client
|
| 25 |
+
pc = Pinecone(api_key=api_key)
|
| 26 |
+
|
| 27 |
+
from pinecone import ServerlessSpec
|
| 28 |
+
|
| 29 |
+
cloud = os.environ.get('PINECONE_CLOUD') or 'aws'
|
| 30 |
+
region = os.environ.get('PINECONE_REGION') or 'us-east-1'
|
| 31 |
+
|
| 32 |
+
spec = ServerlessSpec(cloud=cloud, region=region)
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
# connect to index
|
| 36 |
+
index = pc.Index(index_name)
|
| 37 |
+
st.write('Successfully connected to your Search Engine DB!')
|
| 38 |
+
st.write('Start searching...')
|
|
|
|
|
|
|
| 39 |
|
| 40 |
+
|
| 41 |
+
query = st.text_input("Enter a search query:", "")
|
| 42 |
+
|
| 43 |
+
# If the user has entered a search query, search the Pinecone index with the query
|
| 44 |
+
if query:
|
| 45 |
+
# Upsert the embeddings for the query into the Pinecone index
|
| 46 |
+
query_embeddings = model.encode(query).tolist()
|
| 47 |
+
# now query
|
| 48 |
+
xc = index.query(vector=query_embeddings, top_k=10, namespace=namespace, include_metadata=True)
|
| 49 |
+
|
| 50 |
+
# Display the search results
|
| 51 |
+
st.write(f"Search results for '{query}':")
|
| 52 |
+
for result in xc['matches']:
|
| 53 |
+
st.write(f"{round(result['score'], 2)}: {result['metadata']['meta_text']}")
|