Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -89,10 +89,12 @@ def process_pdf(pdf_file):
|
|
89 |
# combine text chunks and image captions
|
90 |
docs = chunks + captions
|
91 |
|
92 |
-
|
93 |
vectors = embeddings.embed_documents(docs)
|
94 |
-
|
95 |
-
|
|
|
|
|
96 |
|
97 |
status = f"β
Indexed β {len(chunks)} text chunks + {len(captions)} captions"
|
98 |
return os.path.basename(pdf_file.name), status, gr.update(interactive=True)
|
|
|
89 |
# combine text chunks and image captions
|
90 |
docs = chunks + captions
|
91 |
|
92 |
+
# embed and index
|
93 |
vectors = embeddings.embed_documents(docs)
|
94 |
+
# FAISS.from_embeddings expects list of (text, embedding) pairs
|
95 |
+
pairs = list(zip(docs, vectors))
|
96 |
+
index = FAISS.from_embeddings(pairs)
|
97 |
+
retriever = index.as_retriever(search_kwargs={"k":2})(search_kwargs={"k":2})
|
98 |
|
99 |
status = f"β
Indexed β {len(chunks)} text chunks + {len(captions)} captions"
|
100 |
return os.path.basename(pdf_file.name), status, gr.update(interactive=True)
|