captain-awesome commited on
Commit
03fa056
1 Parent(s): 1fd7d63

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -13
app.py CHANGED
@@ -354,23 +354,40 @@ def retrieve_bot_answer(query):
354
  def main():
355
  st.title("Docuverse")
356
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
357
  # Upload files
358
  uploaded_files = st.file_uploader("Upload your documents", type=["pdf", "md", "txt", "csv", "py", "epub", "html", "ppt", "pptx", "doc", "docx", "odt", "ipynb"], accept_multiple_files=True)
359
  loaded_documents = []
360
  if uploaded_files:
361
- # Process uploaded files
362
- for uploaded_file in uploaded_files:
363
- st.write(f"Uploaded: {uploaded_file}")
364
- st.write(f"Uploaded: {uploaded_file.name}")
365
- st.write(f"Uploaded: {type(uploaded_file.name)}")
366
- ext = os.path.splitext(uploaded_file.name)[-1][1:].lower()
367
- st.write(f"Uploaded: {ext}")
368
- if ext in FILE_LOADER_MAPPING:
369
- loader_class, loader_args = FILE_LOADER_MAPPING[ext]
370
- loader = loader_class(uploaded_file, **loader_args)
371
- else:
372
- loader = UnstructuredFileLoader(uploaded_file)
373
- loaded_documents.extend(loader.load())
374
 
375
  st.write("Chat with the Document:")
376
  query = st.text_input("Ask a question:")
 
354
  def main():
355
  st.title("Docuverse")
356
 
357
+ # # Upload files
358
+ # uploaded_files = st.file_uploader("Upload your documents", type=["pdf", "md", "txt", "csv", "py", "epub", "html", "ppt", "pptx", "doc", "docx", "odt", "ipynb"], accept_multiple_files=True)
359
+ # loaded_documents = []
360
+ # if uploaded_files:
361
+ # # Process uploaded files
362
+ # for uploaded_file in uploaded_files:
363
+ # st.write(f"Uploaded: {uploaded_file}")
364
+ # st.write(f"Uploaded: {uploaded_file.name}")
365
+ # st.write(f"Uploaded: {type(uploaded_file.name)}")
366
+ # ext = os.path.splitext(uploaded_file.name)[-1][1:].lower()
367
+ # st.write(f"Uploaded: {ext}")
368
+ # if ext in FILE_LOADER_MAPPING:
369
+ # loader_class, loader_args = FILE_LOADER_MAPPING[ext]
370
+ # loader = loader_class(uploaded_file, **loader_args)
371
+ # else:
372
+ # loader = UnstructuredFileLoader(uploaded_file)
373
+ # loaded_documents.extend(loader.load())
374
  # Upload files
375
  uploaded_files = st.file_uploader("Upload your documents", type=["pdf", "md", "txt", "csv", "py", "epub", "html", "ppt", "pptx", "doc", "docx", "odt", "ipynb"], accept_multiple_files=True)
376
  loaded_documents = []
377
  if uploaded_files:
378
+ # Create a temporary directory
379
+ with tempfile.TemporaryDirectory() as td:
380
+ # Move the uploaded files to the temporary directory
381
+ for uploaded_file in uploaded_files:
382
+ uploaded_file.save(os.path.join(td, uploaded_file.name))
383
+
384
+ # Process the files in the temporary directory
385
+ for file in os.listdir(td):
386
+ ext = os.path.splitext(file)[-1][1:].lower()
387
+ if ext in FILE_LOADER_MAPPING:
388
+ loader_class, loader_args = FILE_LOADER_MAPPING[ext]
389
+ loader = loader_class(os.path.join(td, file), **loader_args)
390
+ loaded_documents.extend(loader.load())
391
 
392
  st.write("Chat with the Document:")
393
  query = st.text_input("Ask a question:")