DeepSoft-Tech commited on
Commit
ae68bc9
1 Parent(s): f935900

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -31
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
- api_key = os.environ.get('PINECONE_API_KEY') or key
22
-
23
- # configure client
24
- pc = Pinecone(api_key=api_key)
25
-
26
- from pinecone import ServerlessSpec
27
-
28
- cloud = os.environ.get('PINECONE_CLOUD') or 'aws'
29
- region = os.environ.get('PINECONE_REGION') or 'us-east-1'
30
-
31
- spec = ServerlessSpec(cloud=cloud, region=region)
32
-
33
-
34
- # connect to index
35
- index = pc.Index(index_name)
36
- st.write('Successfully connected to your Search Engine DB!')
37
- st.write('Start searching...')
38
-
39
-
40
- query = st.text_input("Enter a search query:", "")
41
 
42
- # If the user has entered a search query, search the Pinecone index with the query
43
- if query:
44
- # Upsert the embeddings for the query into the Pinecone index
45
- query_embeddings = model.encode(query).tolist()
46
- # now query
47
- xc = index.query(vector=query_embeddings, top_k=10, namespace=namespace, include_metadata=True)
48
-
49
- # Display the search results
50
- st.write(f"Search results for '{query}':")
51
- for result in xc['matches']:
52
- st.write(f"{round(result['score'], 2)}: {result['metadata']['meta_text']}")
 
 
 
 
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']}")