DeepSoft-Tech commited on
Commit
e5bc3ec
1 Parent(s): 9fdae17

Update app.py

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