Spaces:
Runtime error
Runtime error
Commit
·
1852f2a
1
Parent(s):
7f97da4
Update app.py
Browse files
app.py
CHANGED
@@ -362,46 +362,29 @@ def main():
|
|
362 |
loaded_documents = []
|
363 |
|
364 |
if uploaded_files:
|
365 |
-
if not uploaded_files:
|
366 |
-
st.warning("Please upload some documents.")
|
367 |
# Create a temporary directory
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
# # Check if the extension is in FILE_LOADER_MAPPING
|
391 |
-
# if ext in FILE_LOADER_MAPPING:
|
392 |
-
# loader_class, loader_args = FILE_LOADER_MAPPING[ext]
|
393 |
-
# st.write(f"loader_class: {loader_class}")
|
394 |
-
# # Save the uploaded file to the temporary directory
|
395 |
-
# # file_path = os.path.join(td, uploaded_file.name)
|
396 |
-
# with open(os.path.join(td, uploaded_file), 'wb') as temp_file:
|
397 |
-
# temp_file.write(uploaded_file.read())
|
398 |
-
# # with open(file_path, 'wb') as temp_file:
|
399 |
-
# # temp_file.write(uploaded_file.read())
|
400 |
-
|
401 |
-
# # Use Langchain loader to process the file
|
402 |
-
# loader = loader_class(os.path.join(td, file), **loader_args)
|
403 |
-
# loaded_documents.extend(loader.load())
|
404 |
-
# st.write(f"loaded_documents: {loaded_documents}")
|
405 |
st.write(f"loaded_documents: {loaded_documents}")
|
406 |
st.write("Chat with the Document:")
|
407 |
query = st.text_input("Ask a question:")
|
|
|
362 |
loaded_documents = []
|
363 |
|
364 |
if uploaded_files:
|
|
|
|
|
365 |
# Create a temporary directory
|
366 |
+
with tempfile.TemporaryDirectory() as td:
|
367 |
+
# Move the uploaded files to the temporary directory and process them
|
368 |
+
for uploaded_file in uploaded_files:
|
369 |
+
st.write(f"Uploaded: {uploaded_file.name}")
|
370 |
+
ext = os.path.splitext(uploaded_file.name)[-1][1:].lower()
|
371 |
+
st.write(f"Uploaded: {ext}")
|
372 |
+
|
373 |
+
# Check if the extension is in FILE_LOADER_MAPPING
|
374 |
+
if ext in FILE_LOADER_MAPPING:
|
375 |
+
loader_class, loader_args = FILE_LOADER_MAPPING[ext]
|
376 |
+
|
377 |
+
# Save the uploaded file to the temporary directory
|
378 |
+
file_path = os.path.join(td, uploaded_file.name)
|
379 |
+
with open(file_path, 'wb') as temp_file:
|
380 |
+
temp_file.write(uploaded_file.read())
|
381 |
+
|
382 |
+
# Use Langchain loader to process the file
|
383 |
+
loader = loader_class(file_path, **loader_args)
|
384 |
+
loaded_documents.extend(loader.load())
|
385 |
+
else:
|
386 |
+
st.warning(f"Unsupported file extension: {ext}")
|
387 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
388 |
st.write(f"loaded_documents: {loaded_documents}")
|
389 |
st.write("Chat with the Document:")
|
390 |
query = st.text_input("Ask a question:")
|