Spaces:
Sleeping
Sleeping
Commit
Β·
b6b712b
1
Parent(s):
d999285
added 'view list of all documents'
Browse files
app.py
CHANGED
|
@@ -35,6 +35,16 @@ with open('hashed_password.pkl','rb') as f:
|
|
| 35 |
# Whether the file upload should be enabled or not
|
| 36 |
DISABLE_FILE_UPLOAD = bool(os.getenv("DISABLE_FILE_UPLOAD"))
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
# Define a function to handle file uploads
|
| 39 |
def upload_files():
|
| 40 |
uploaded_files = upload_container.file_uploader(
|
|
@@ -42,6 +52,7 @@ def upload_files():
|
|
| 42 |
)
|
| 43 |
return uploaded_files
|
| 44 |
|
|
|
|
| 45 |
# Define a function to process a single file
|
| 46 |
def process_file(data_file, preprocesor, document_store):
|
| 47 |
# read file and add content
|
|
@@ -79,7 +90,7 @@ def upload_document():
|
|
| 79 |
# Call the process_file function for each uploaded file
|
| 80 |
if args.store == 'inmemory':
|
| 81 |
processed_data = process_file(data_file, preprocesor, document_store)
|
| 82 |
-
upload_container.write(str(data_file.name) + " β
")
|
| 83 |
except Exception as e:
|
| 84 |
upload_container.write(str(data_file.name) + " β ")
|
| 85 |
upload_container.write("_This file could not be parsed, see the logs for more information._")
|
|
@@ -90,11 +101,11 @@ def reset_documents():
|
|
| 90 |
st.session_state.data_files = None
|
| 91 |
document_store.delete_documents()
|
| 92 |
|
| 93 |
-
|
| 94 |
try:
|
| 95 |
args = parser.parse_args()
|
| 96 |
preprocesor = start_preprocessor_node()
|
| 97 |
document_store = start_document_store(type=args.store)
|
|
|
|
| 98 |
retriever = start_retriever(document_store)
|
| 99 |
reader = start_reader()
|
| 100 |
st.set_page_config(
|
|
@@ -156,6 +167,7 @@ try:
|
|
| 156 |
data_files = upload_files()
|
| 157 |
upload_document()
|
| 158 |
st.session_state.sidebar_state = 'collapsed'
|
|
|
|
| 159 |
|
| 160 |
# File upload block
|
| 161 |
# if not DISABLE_FILE_UPLOAD:
|
|
|
|
| 35 |
# Whether the file upload should be enabled or not
|
| 36 |
DISABLE_FILE_UPLOAD = bool(os.getenv("DISABLE_FILE_UPLOAD"))
|
| 37 |
|
| 38 |
+
|
| 39 |
+
def show_documents_list(retrieved_documents):
|
| 40 |
+
data = []
|
| 41 |
+
for i, document in enumerate(retrieved_documents):
|
| 42 |
+
# Truncate the content
|
| 43 |
+
truncated_content = (document.content[:150] + '...') if len(document.content) > 150 else document.content
|
| 44 |
+
data.append([i + 1, document.meta['name'], truncated_content])
|
| 45 |
+
df = pd.DataFrame(data, columns=['Ranked Context', 'Document Name', 'Content'])
|
| 46 |
+
return df
|
| 47 |
+
|
| 48 |
# Define a function to handle file uploads
|
| 49 |
def upload_files():
|
| 50 |
uploaded_files = upload_container.file_uploader(
|
|
|
|
| 52 |
)
|
| 53 |
return uploaded_files
|
| 54 |
|
| 55 |
+
|
| 56 |
# Define a function to process a single file
|
| 57 |
def process_file(data_file, preprocesor, document_store):
|
| 58 |
# read file and add content
|
|
|
|
| 90 |
# Call the process_file function for each uploaded file
|
| 91 |
if args.store == 'inmemory':
|
| 92 |
processed_data = process_file(data_file, preprocesor, document_store)
|
| 93 |
+
#upload_container.write(str(data_file.name) + " β
")
|
| 94 |
except Exception as e:
|
| 95 |
upload_container.write(str(data_file.name) + " β ")
|
| 96 |
upload_container.write("_This file could not be parsed, see the logs for more information._")
|
|
|
|
| 101 |
st.session_state.data_files = None
|
| 102 |
document_store.delete_documents()
|
| 103 |
|
|
|
|
| 104 |
try:
|
| 105 |
args = parser.parse_args()
|
| 106 |
preprocesor = start_preprocessor_node()
|
| 107 |
document_store = start_document_store(type=args.store)
|
| 108 |
+
document_store.get_all_documents()
|
| 109 |
retriever = start_retriever(document_store)
|
| 110 |
reader = start_reader()
|
| 111 |
st.set_page_config(
|
|
|
|
| 167 |
data_files = upload_files()
|
| 168 |
upload_document()
|
| 169 |
st.session_state.sidebar_state = 'collapsed'
|
| 170 |
+
st.table(show_documents_list(document_store.get_all_documents()))
|
| 171 |
|
| 172 |
# File upload block
|
| 173 |
# if not DISABLE_FILE_UPLOAD:
|