Spaces:
Sleeping
Sleeping
Shroogawh24
commited on
Commit
•
7f402d8
1
Parent(s):
250878c
Update app.py
Browse files
app.py
CHANGED
@@ -13,13 +13,13 @@ from sentence_transformers import SentenceTransformer
|
|
13 |
|
14 |
embeddings = OpenAIEmbeddings()
|
15 |
|
16 |
-
|
17 |
|
18 |
# Set the OpenAI API key
|
19 |
openai.api_key = os.getenv("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")
|
20 |
|
21 |
# Load the FAISS index using LangChain's FAISS implementation
|
22 |
-
db = FAISS.load_local("Faiss_indexes",
|
23 |
parser = StrOutputParser()
|
24 |
|
25 |
# Load your data (e.g., a DataFrame)
|
@@ -27,7 +27,7 @@ df = pd.read_pickle('df_news (1).pkl')
|
|
27 |
|
28 |
# Search function to retrieve relevant documents
|
29 |
def search(query):
|
30 |
-
query_embedding =
|
31 |
D, I = db.similarity_search_with_score(query_embedding, k=10)
|
32 |
results = []
|
33 |
for idx in I[0]:
|
|
|
13 |
|
14 |
embeddings = OpenAIEmbeddings()
|
15 |
|
16 |
+
embedder = SentenceTransformer('all-mpnet-base-v2')
|
17 |
|
18 |
# Set the OpenAI API key
|
19 |
openai.api_key = os.getenv("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")
|
20 |
|
21 |
# Load the FAISS index using LangChain's FAISS implementation
|
22 |
+
db = FAISS.load_local("Faiss_indexes", embedder, allow_dangerous_deserialization=True)
|
23 |
parser = StrOutputParser()
|
24 |
|
25 |
# Load your data (e.g., a DataFrame)
|
|
|
27 |
|
28 |
# Search function to retrieve relevant documents
|
29 |
def search(query):
|
30 |
+
query_embedding = embedder.embed_query(query).reshape(1, -1).astype('float32')
|
31 |
D, I = db.similarity_search_with_score(query_embedding, k=10)
|
32 |
results = []
|
33 |
for idx in I[0]:
|