Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -15,6 +15,8 @@ from langchain_core.documents import Document
|
|
15 |
from huggingface_hub import InferenceClient
|
16 |
import inspect
|
17 |
import logging
|
|
|
|
|
18 |
|
19 |
|
20 |
# Set up basic configuration for logging
|
@@ -85,10 +87,19 @@ def update_vectors(files, parser):
|
|
85 |
for file in files:
|
86 |
logging.info(f"Processing file: {file.name}")
|
87 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
# Save the uploaded file
|
89 |
os.makedirs("uploaded_files", exist_ok=True)
|
90 |
file_path = os.path.join("uploaded_files", file.name)
|
91 |
-
|
|
|
|
|
|
|
92 |
|
93 |
data = load_document(file_path, parser)
|
94 |
logging.info(f"Loaded {len(data)} chunks from {file.name}")
|
|
|
15 |
from huggingface_hub import InferenceClient
|
16 |
import inspect
|
17 |
import logging
|
18 |
+
import tempfile
|
19 |
+
import shutil
|
20 |
|
21 |
|
22 |
# Set up basic configuration for logging
|
|
|
87 |
for file in files:
|
88 |
logging.info(f"Processing file: {file.name}")
|
89 |
try:
|
90 |
+
# Create a temporary file
|
91 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix='.pdf') as temp_file:
|
92 |
+
# Write the content to the temporary file
|
93 |
+
temp_file.write(file.read())
|
94 |
+
temp_file_path = temp_file.name
|
95 |
+
|
96 |
# Save the uploaded file
|
97 |
os.makedirs("uploaded_files", exist_ok=True)
|
98 |
file_path = os.path.join("uploaded_files", file.name)
|
99 |
+
shutil.copy(temp_file_path, file_path)
|
100 |
+
|
101 |
+
# Remove the temporary file
|
102 |
+
os.unlink(temp_file_path)
|
103 |
|
104 |
data = load_document(file_path, parser)
|
105 |
logging.info(f"Loaded {len(data)} chunks from {file.name}")
|