Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -33,9 +33,23 @@ def extract_text_from_pdf(pdf_path):
|
|
33 |
def create_vector_db(text_chunks):
|
34 |
"""Embeds text chunks and adds them to FAISS index"""
|
35 |
global documents, index
|
|
|
36 |
documents = text_chunks
|
37 |
embeddings = embed_model.encode(text_chunks)
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
def search_relevant_text(query):
|
41 |
"""Finds the most relevant text chunk for the given query"""
|
|
|
33 |
def create_vector_db(text_chunks):
|
34 |
"""Embeds text chunks and adds them to FAISS index"""
|
35 |
global documents, index
|
36 |
+
|
37 |
documents = text_chunks
|
38 |
embeddings = embed_model.encode(text_chunks)
|
39 |
+
|
40 |
+
# Convert embeddings to np.float32 for FAISS
|
41 |
+
embeddings = np.array(embeddings, dtype=np.float32)
|
42 |
+
|
43 |
+
# Ensure that embeddings have the correct shape (should be 2D, with each vector having the right dimension)
|
44 |
+
if embeddings.ndim == 1: # If only one embedding, reshape it
|
45 |
+
embeddings = embeddings.reshape(1, -1)
|
46 |
+
|
47 |
+
# Add embeddings to the FAISS index
|
48 |
+
index.add(embeddings)
|
49 |
+
|
50 |
+
# Check if adding was successful (optional)
|
51 |
+
if index.ntotal == 0:
|
52 |
+
print("Error: FAISS index is empty after adding embeddings.")
|
53 |
|
54 |
def search_relevant_text(query):
|
55 |
"""Finds the most relevant text chunk for the given query"""
|