Spaces:
Paused
Paused
File size: 900 Bytes
2624a11 7bc489f 562d4c9 7bc489f 2624a11 9a71317 7bc489f 2624a11 7bc489f 2624a11 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
from langchain_community.document_loaders import PyMuPDFLoader, TextLoader
from langchain_community.vectorstores import Qdrant
import os
def process_file(uploaded_file):
# save the file temporarily
temp_file = "./temp.pdf"
with open(temp_file, "wb") as file:
file.write(uploaded_file.content)
file_name = uploaded_file.name
documents = []
if uploaded_file.path.endswith(".pdf"):
loader = PyMuPDFLoader(temp_file)
docs = loader.load()
documents.extend(docs)
else:
loader = TextLoader(tmp_location)
docs = loader.load()
documents.extend(docs)
return documents
def add_to_qdrant(documents, embeddings, qdrant_client, collection_name):
Qdrant.from_documents(
documents,
embeddings,
url=qdrant_client.url,
prefer_grpc=True,
collection_name=collection_name,
) |