Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import streamlit as st
|
2 |
|
3 |
-
from transformers import pipeline
|
4 |
from pinecone import Pinecone, ServerlessSpec
|
5 |
from sentence_transformers import SentenceTransformer, util
|
6 |
|
@@ -10,7 +10,7 @@ bi_encoder.max_seq_length = 256 # Truncate long documents to 256 tokens
|
|
10 |
|
11 |
# Store the index as a variable
|
12 |
INDEX_NAME = 'cl-search-idx'
|
13 |
-
|
14 |
pc_api_key= '3f916d01-2a69-457d-85eb-966c5d1849a8' #AWS
|
15 |
pc = Pinecone(api_key=pc_api_key)
|
16 |
index = pc.Index(name=INDEX_NAME)
|
@@ -25,11 +25,18 @@ def query_from_pinecone(index,namespace, question_embedding, top_k=3):
|
|
25 |
include_metadata=True # gets the metadata (dates, text, etc)
|
26 |
).get('matches')
|
27 |
|
28 |
-
|
29 |
QUESTION=st.text_area('Ask a question -e.g How to prepare for Verbal section for CAT?') ##' How to prepare for Verbal section ?'
|
30 |
-
question_embedding = bi_encoder.encode(QUESTION, convert_to_tensor=True)
|
31 |
-
resp= query_from_pinecone(index,NAMESPACE, question_embedding.tolist(), 3)
|
32 |
-
out= resp[0]['metadata']['text']
|
33 |
-
#+ '\n*************\n'+ resp[1]['metadata']['text'] + '\n*************\n'+ resp[2]['metadata']['text']
|
34 |
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
|
3 |
+
#from transformers import pipeline
|
4 |
from pinecone import Pinecone, ServerlessSpec
|
5 |
from sentence_transformers import SentenceTransformer, util
|
6 |
|
|
|
10 |
|
11 |
# Store the index as a variable
|
12 |
INDEX_NAME = 'cl-search-idx'
|
13 |
+
|
14 |
pc_api_key= '3f916d01-2a69-457d-85eb-966c5d1849a8' #AWS
|
15 |
pc = Pinecone(api_key=pc_api_key)
|
16 |
index = pc.Index(name=INDEX_NAME)
|
|
|
25 |
include_metadata=True # gets the metadata (dates, text, etc)
|
26 |
).get('matches')
|
27 |
|
|
|
28 |
QUESTION=st.text_area('Ask a question -e.g How to prepare for Verbal section for CAT?') ##' How to prepare for Verbal section ?'
|
|
|
|
|
|
|
|
|
29 |
|
30 |
+
if QUESTION:
|
31 |
+
question_embedding = bi_encoder.encode(QUESTION, convert_to_tensor=True)
|
32 |
+
|
33 |
+
ns='full'
|
34 |
+
resp= query_from_pinecone(index,ns, question_embedding.tolist(), 3)
|
35 |
+
if len(resp)>0:
|
36 |
+
out= resp[0]['metadata']['data']
|
37 |
+
url= "Matching url "+resp[0]['id']
|
38 |
+
#+ '\n*************\n'+ resp[1]['metadata']['text'] + '\n*************\n'+ resp[2]['metadata']['text']
|
39 |
+
st.write(url)
|
40 |
+
st.write(out)
|
41 |
+
else:
|
42 |
+
st.write("No matches for query")
|