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