captain-awesome commited on
Commit
1852f2a
·
1 Parent(s): 7f97da4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -39
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
- # with tempfile.TemporaryDirectory() as td:
369
- # # Move the uploaded files to the temporary directory and process them
370
- # for uploaded_file in uploaded_files:
371
- # st.write(f"Uploaded: {uploaded_file.name}")
372
- # ext = os.path.splitext(uploaded_file.name)[-1][1:].lower()
373
- # st.write(f"Uploaded: {ext}")
374
- for uploaded_file in uploaded_files:
375
- # Check if the extension is in FILE_LOADER_MAPPING
376
- ext = os.path.splitext(uploaded_file.name)[-1][1:].lower()
377
- if ext in FILE_LOADER_MAPPING:
378
- loader_class, loader_args = FILE_LOADER_MAPPING[ext]
379
- st.write(f"loader_class: {loader_class}")
380
- # Save the uploaded file to the temporary directory
381
- # file_path = os.path.join(td, uploaded_file.name)
382
- with open(os.path.join(td, uploaded_file), 'wb') as temp_file:
383
- temp_file.write(uploaded_file.read())
384
- # with open(file_path, 'wb') as temp_file:
385
- # temp_file.write(uploaded_file.read())
386
-
387
- # Use Langchain loader to process the file
388
- loader = loader_class(os.path.join(td, file), **loader_args)
389
- loaded_documents.extend(loader.load())
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:")