DeepSoft-Tech commited on
Commit
ecbad34
·
verified ·
1 Parent(s): 4e50689

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -30
app.py CHANGED
@@ -1,9 +1,16 @@
1
  import streamlit as st
2
  import os
3
  from pinecone import Pinecone
 
 
4
 
 
 
 
 
 
5
  # initialize connection to pinecone (get API key at app.pinecone.io)
6
- api_key = os.environ.get('PINECONE_API_KEY') or '68f4d786-9797-4c17-8620-9b5302a3823b'
7
 
8
  # configure client
9
  pc = Pinecone(api_key=api_key)
@@ -15,32 +22,10 @@ region = os.environ.get('PINECONE_REGION') or 'us-east-1'
15
 
16
  spec = ServerlessSpec(cloud=cloud, region=region)
17
 
18
- index_name = 'search-index'
19
-
20
- import time
21
-
22
- existing_indexes = [
23
- index_info["name"] for index_info in pc.list_indexes()
24
- ]
25
-
26
- # # check if index already exists (it shouldn't if this is first time)
27
- # if index_name not in existing_indexes:
28
- # # if does not exist, create index
29
- # pc.create_index(
30
- # index_name,
31
- # dimension=384, # dimensionality of minilm
32
- # metric='cosine',
33
- # spec=spec
34
- # )
35
- # # wait for index to be initialized
36
- # while not pc.describe_index(index_name).status['ready']:
37
- # time.sleep(1)
38
 
39
  # connect to index
40
  index = pc.Index(index_name)
41
- time.sleep(1)
42
- # view index stats
43
- index.describe_index_stats()
44
 
45
  from sentence_transformers import SentenceTransformer
46
  # import torch
@@ -50,11 +35,6 @@ from sentence_transformers import SentenceTransformer
50
  model = SentenceTransformer('intfloat/e5-small')
51
 
52
 
53
- # Set up the Streamlit app
54
- st.set_page_config(page_title="Hotel Search", page_icon=":hotel:", layout="wide")
55
-
56
- # Set up the Streamlit app title and search bar
57
- st.title("Hotel Search")
58
  query = st.text_input("Enter a search query:", "")
59
 
60
  # If the user has entered a search query, search the Pinecone index with the query
@@ -62,7 +42,7 @@ if query:
62
  # Upsert the embeddings for the query into the Pinecone index
63
  query_embeddings = model.encode(query).tolist()
64
  # now query
65
- xc = index.query(vector=query_embeddings, top_k=5, namespace="hotel-detail", include_metadata=True)
66
 
67
  # Display the search results
68
  st.write(f"Search results for '{query}':")
 
1
  import streamlit as st
2
  import os
3
  from pinecone import Pinecone
4
+ # Set up the Streamlit app
5
+ st.set_page_config(page_title="Hotel Search", page_icon=":hotel:", layout="wide")
6
 
7
+ # Set up the Streamlit app title and search bar
8
+ st.title("Hotel Search")
9
+ index_name = st.text_input("Enter a database name:", "")
10
+ key = st.text_input("Enter a key:", "")
11
+ namespace = st.text_input("Enter a table name:", "")
12
  # initialize connection to pinecone (get API key at app.pinecone.io)
13
+ api_key = os.environ.get('PINECONE_API_KEY') or key
14
 
15
  # configure client
16
  pc = Pinecone(api_key=api_key)
 
22
 
23
  spec = ServerlessSpec(cloud=cloud, region=region)
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
  # connect to index
27
  index = pc.Index(index_name)
28
+
 
 
29
 
30
  from sentence_transformers import SentenceTransformer
31
  # import torch
 
35
  model = SentenceTransformer('intfloat/e5-small')
36
 
37
 
 
 
 
 
 
38
  query = st.text_input("Enter a search query:", "")
39
 
40
  # If the user has entered a search query, search the Pinecone index with the query
 
42
  # Upsert the embeddings for the query into the Pinecone index
43
  query_embeddings = model.encode(query).tolist()
44
  # now query
45
+ xc = index.query(vector=query_embeddings, top_k=10, namespace=namespace, include_metadata=True)
46
 
47
  # Display the search results
48
  st.write(f"Search results for '{query}':")