Spaces:
Runtime error
Runtime error
Commit
·
2476b8a
1
Parent(s):
f15d870
Update app.py
Browse files
app.py
CHANGED
@@ -355,40 +355,30 @@ def retrieve_bot_answer(query):
|
|
355 |
def main():
|
356 |
st.title("Docuverse")
|
357 |
|
358 |
-
# # Upload files
|
359 |
-
# 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)
|
360 |
-
# loaded_documents = []
|
361 |
-
# if uploaded_files:
|
362 |
-
# # Process uploaded files
|
363 |
-
# for uploaded_file in uploaded_files:
|
364 |
-
# st.write(f"Uploaded: {uploaded_file}")
|
365 |
-
# st.write(f"Uploaded: {uploaded_file.name}")
|
366 |
-
# st.write(f"Uploaded: {type(uploaded_file.name)}")
|
367 |
-
# ext = os.path.splitext(uploaded_file.name)[-1][1:].lower()
|
368 |
-
# st.write(f"Uploaded: {ext}")
|
369 |
-
# if ext in FILE_LOADER_MAPPING:
|
370 |
-
# loader_class, loader_args = FILE_LOADER_MAPPING[ext]
|
371 |
-
# loader = loader_class(uploaded_file, **loader_args)
|
372 |
-
# else:
|
373 |
-
# loader = UnstructuredFileLoader(uploaded_file)
|
374 |
-
# loaded_documents.extend(loader.load())
|
375 |
# Upload files
|
376 |
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)
|
377 |
loaded_documents = []
|
|
|
378 |
if uploaded_files:
|
379 |
# Create a temporary directory
|
380 |
with tempfile.TemporaryDirectory() as td:
|
381 |
-
# Move the uploaded files to the temporary directory
|
382 |
for uploaded_file in uploaded_files:
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
|
|
387 |
if ext in FILE_LOADER_MAPPING:
|
388 |
loader_class, loader_args = FILE_LOADER_MAPPING[ext]
|
389 |
-
|
|
|
|
|
|
|
390 |
temp_file.write(uploaded_file.read())
|
391 |
-
|
|
|
|
|
392 |
loaded_documents.extend(loader.load())
|
393 |
|
394 |
st.write("Chat with the Document:")
|
|
|
355 |
def main():
|
356 |
st.title("Docuverse")
|
357 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
358 |
# Upload files
|
359 |
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)
|
360 |
loaded_documents = []
|
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 |
+
|
375 |
+
# Save the uploaded file to the temporary directory
|
376 |
+
file_path = os.path.join(td, uploaded_file.name)
|
377 |
+
with open(file_path, 'wb') as temp_file:
|
378 |
temp_file.write(uploaded_file.read())
|
379 |
+
|
380 |
+
# Use Langchain loader to process the file
|
381 |
+
loader = loader_class(file_path, **loader_args)
|
382 |
loaded_documents.extend(loader.load())
|
383 |
|
384 |
st.write("Chat with the Document:")
|