captain-awesome commited on
Commit
67ad565
·
1 Parent(s): 34e4c94

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -22
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
- # 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
-
371
- # Check if the extension is in FILE_LOADER_MAPPING
372
- if ext in FILE_LOADER_MAPPING:
373
- loader_class, loader_args = FILE_LOADER_MAPPING[ext]
374
- st.write(f"loader_class: {loader_class}")
375
- # Save the uploaded file to the temporary directory
376
- # file_path = os.path.join(td, uploaded_file.name)
377
- with open(os.path.join(td, uploaded_file), 'wb') as temp_file:
378
- temp_file.write(uploaded_file.read())
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(os.path.join(td, file), **loader_args)
384
- loaded_documents.extend(loader.load())
385
- st.write(f"loaded_documents: {loaded_documents}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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:")