Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -88,15 +88,15 @@ def update_vectors(files, parser):
|
|
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.
|
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(
|
100 |
|
101 |
# Remove the temporary file
|
102 |
os.unlink(temp_file_path)
|
@@ -106,8 +106,8 @@ def update_vectors(files, parser):
|
|
106 |
all_data.extend(data)
|
107 |
total_chunks += len(data)
|
108 |
# Append new documents instead of replacing
|
109 |
-
if not any(doc["name"] == file.name for doc in uploaded_documents):
|
110 |
-
uploaded_documents.append({"name": file.name, "selected": True})
|
111 |
logging.info(f"Added new document to uploaded_documents: {file.name}")
|
112 |
else:
|
113 |
logging.info(f"Document already exists in uploaded_documents: {file.name}")
|
|
|
88 |
logging.info(f"Processing file: {file.name}")
|
89 |
try:
|
90 |
# Create a temporary file
|
91 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix='.pdf', mode='wb') as temp_file:
|
92 |
# Write the content to the temporary file
|
93 |
+
temp_file.write(file.name.encode('utf-8')) # Write the file path
|
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", os.path.basename(file.name))
|
99 |
+
shutil.copy(file.name, file_path) # Copy the actual file
|
100 |
|
101 |
# Remove the temporary file
|
102 |
os.unlink(temp_file_path)
|
|
|
106 |
all_data.extend(data)
|
107 |
total_chunks += len(data)
|
108 |
# Append new documents instead of replacing
|
109 |
+
if not any(doc["name"] == os.path.basename(file.name) for doc in uploaded_documents):
|
110 |
+
uploaded_documents.append({"name": os.path.basename(file.name), "selected": True})
|
111 |
logging.info(f"Added new document to uploaded_documents: {file.name}")
|
112 |
else:
|
113 |
logging.info(f"Document already exists in uploaded_documents: {file.name}")
|