Spaces:
Paused
Paused
danicafisher
commited on
Commit
•
7bc489f
1
Parent(s):
13377ce
Update helper_functions.py
Browse files- helper_functions.py +10 -3
helper_functions.py
CHANGED
@@ -1,14 +1,21 @@
|
|
1 |
from langchain_community.document_loaders import PyMuPDFLoader, TextLoader
|
2 |
from langchain_community.vectorstores import Qdrant
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
-
def process_file(file):
|
5 |
documents = []
|
6 |
if file.path.endswith(".pdf"):
|
7 |
-
loader = PyMuPDFLoader(
|
8 |
docs = loader.load()
|
9 |
documents.extend(docs)
|
10 |
else:
|
11 |
-
loader = TextLoader(
|
12 |
docs = loader.load()
|
13 |
documents.extend(docs)
|
14 |
return documents
|
|
|
1 |
from langchain_community.document_loaders import PyMuPDFLoader, TextLoader
|
2 |
from langchain_community.vectorstores import Qdrant
|
3 |
+
import os
|
4 |
+
|
5 |
+
def process_file(uploaded_file):
|
6 |
+
# save the file temporarily
|
7 |
+
temp_file = "./temp.pdf"
|
8 |
+
with open(temp_file, "wb") as file:
|
9 |
+
file.write(uploaded_file.getvalue())
|
10 |
+
file_name = uploaded_file.name
|
11 |
|
|
|
12 |
documents = []
|
13 |
if file.path.endswith(".pdf"):
|
14 |
+
loader = PyMuPDFLoader(temp_file)
|
15 |
docs = loader.load()
|
16 |
documents.extend(docs)
|
17 |
else:
|
18 |
+
loader = TextLoader(tmp_location)
|
19 |
docs = loader.load()
|
20 |
documents.extend(docs)
|
21 |
return documents
|