Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -350,7 +350,6 @@ def edit_all_documents(container, search_keyword=None):
|
|
| 350 |
st.markdown("### 📑 All Documents" + (f" (Filtered: '{search_keyword}')" if search_keyword else ""))
|
| 351 |
documents = get_documents(container)
|
| 352 |
if search_keyword:
|
| 353 |
-
# Filter documents by search keyword
|
| 354 |
documents = [doc for doc in documents if vector_keyword_search(search_keyword, doc)]
|
| 355 |
if not documents:
|
| 356 |
st.info("No documents match the current filter." if search_keyword else "No documents in this container.")
|
|
@@ -473,7 +472,6 @@ def new_links_record(container):
|
|
| 473 |
st.error(f"Error creating links record: {message}")
|
| 474 |
|
| 475 |
def vector_keyword_search(keyword, doc):
|
| 476 |
-
# Check if keyword exists in any string field of the document
|
| 477 |
keyword = keyword.lower()
|
| 478 |
for key, value in doc.items():
|
| 479 |
if isinstance(value, str) and keyword in value.lower():
|
|
@@ -489,11 +487,11 @@ def search_documents_ui(container):
|
|
| 489 |
with col2:
|
| 490 |
clear_submitted = st.form_submit_button("🗑️ Clear")
|
| 491 |
if search_submitted and keyword:
|
| 492 |
-
st.session_state.
|
| 493 |
st.rerun()
|
| 494 |
if clear_submitted:
|
| 495 |
-
if '
|
| 496 |
-
del st.session_state.
|
| 497 |
st.rerun()
|
| 498 |
|
| 499 |
def validate_and_preprocess_image(file_data, target_size=(576, 1024)):
|
|
@@ -623,8 +621,8 @@ def main():
|
|
| 623 |
st.session_state.selected_database = selected_db
|
| 624 |
st.session_state.selected_container = None
|
| 625 |
st.session_state.current_container = None
|
| 626 |
-
if '
|
| 627 |
-
del st.session_state.
|
| 628 |
st.rerun()
|
| 629 |
|
| 630 |
# Containers Section
|
|
@@ -645,8 +643,8 @@ def main():
|
|
| 645 |
if selected_container != st.session_state.get("selected_container"):
|
| 646 |
st.session_state.selected_container = selected_container
|
| 647 |
st.session_state.current_container = database.get_container_client(selected_container)
|
| 648 |
-
if '
|
| 649 |
-
del st.session_state.
|
| 650 |
st.rerun()
|
| 651 |
|
| 652 |
# Actions Section
|
|
@@ -673,7 +671,7 @@ def main():
|
|
| 673 |
|
| 674 |
# Central Area: Editable Documents with Search Filter
|
| 675 |
if st.session_state.current_container:
|
| 676 |
-
search_keyword = st.session_state.get('
|
| 677 |
edit_all_documents(st.session_state.current_container, search_keyword)
|
| 678 |
else:
|
| 679 |
st.info("Select a database and container to view and edit documents.")
|
|
@@ -689,8 +687,8 @@ def main():
|
|
| 689 |
st.session_state.selected_database = None
|
| 690 |
st.session_state.selected_container = None
|
| 691 |
st.session_state.current_container = None
|
| 692 |
-
if '
|
| 693 |
-
del st.session_state.
|
| 694 |
st.rerun()
|
| 695 |
|
| 696 |
if __name__ == "__main__":
|
|
|
|
| 350 |
st.markdown("### 📑 All Documents" + (f" (Filtered: '{search_keyword}')" if search_keyword else ""))
|
| 351 |
documents = get_documents(container)
|
| 352 |
if search_keyword:
|
|
|
|
| 353 |
documents = [doc for doc in documents if vector_keyword_search(search_keyword, doc)]
|
| 354 |
if not documents:
|
| 355 |
st.info("No documents match the current filter." if search_keyword else "No documents in this container.")
|
|
|
|
| 472 |
st.error(f"Error creating links record: {message}")
|
| 473 |
|
| 474 |
def vector_keyword_search(keyword, doc):
|
|
|
|
| 475 |
keyword = keyword.lower()
|
| 476 |
for key, value in doc.items():
|
| 477 |
if isinstance(value, str) and keyword in value.lower():
|
|
|
|
| 487 |
with col2:
|
| 488 |
clear_submitted = st.form_submit_button("🗑️ Clear")
|
| 489 |
if search_submitted and keyword:
|
| 490 |
+
st.session_state.active_search = keyword # Use a separate key
|
| 491 |
st.rerun()
|
| 492 |
if clear_submitted:
|
| 493 |
+
if 'active_search' in st.session_state:
|
| 494 |
+
del st.session_state.active_search
|
| 495 |
st.rerun()
|
| 496 |
|
| 497 |
def validate_and_preprocess_image(file_data, target_size=(576, 1024)):
|
|
|
|
| 621 |
st.session_state.selected_database = selected_db
|
| 622 |
st.session_state.selected_container = None
|
| 623 |
st.session_state.current_container = None
|
| 624 |
+
if 'active_search' in st.session_state:
|
| 625 |
+
del st.session_state.active_search
|
| 626 |
st.rerun()
|
| 627 |
|
| 628 |
# Containers Section
|
|
|
|
| 643 |
if selected_container != st.session_state.get("selected_container"):
|
| 644 |
st.session_state.selected_container = selected_container
|
| 645 |
st.session_state.current_container = database.get_container_client(selected_container)
|
| 646 |
+
if 'active_search' in st.session_state:
|
| 647 |
+
del st.session_state.active_search
|
| 648 |
st.rerun()
|
| 649 |
|
| 650 |
# Actions Section
|
|
|
|
| 671 |
|
| 672 |
# Central Area: Editable Documents with Search Filter
|
| 673 |
if st.session_state.current_container:
|
| 674 |
+
search_keyword = st.session_state.get('active_search', None)
|
| 675 |
edit_all_documents(st.session_state.current_container, search_keyword)
|
| 676 |
else:
|
| 677 |
st.info("Select a database and container to view and edit documents.")
|
|
|
|
| 687 |
st.session_state.selected_database = None
|
| 688 |
st.session_state.selected_container = None
|
| 689 |
st.session_state.current_container = None
|
| 690 |
+
if 'active_search' in st.session_state:
|
| 691 |
+
del st.session_state.active_search
|
| 692 |
st.rerun()
|
| 693 |
|
| 694 |
if __name__ == "__main__":
|