Wajahat698 commited on
Commit
948f767
·
verified ·
1 Parent(s): 521df97

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -33
app.py CHANGED
@@ -672,6 +672,8 @@ def side():
672
 
673
 
674
  st.sidebar.header("TrustVault®")
 
 
675
  st.sidebar.markdown("""
676
  <style>
677
  .scrollable-container {
@@ -686,65 +688,76 @@ def side():
686
  .button-container {
687
  display: flex;
688
  justify-content: space-between;
689
- gap: 10px;
690
  }
691
  </style>
692
  """, unsafe_allow_html=True)
693
 
694
- # Sidebar: Saved Documents Section
695
- st.sidebar.subheader("Saved Documents")
696
  st.sidebar.markdown('<div class="scrollable-container">', unsafe_allow_html=True)
697
-
698
  try:
699
  # Fetch and display saved documents
700
  docs = db.child("users").child(st.session_state["wix_user_id"]).child("KnowledgeBase").get().val()
701
- doc_names = []
702
- doc_ids = []
703
  if docs:
704
  for doc_id, doc_data in docs.items():
705
- doc_name = doc_data.get('content', 'Document')
706
  st.sidebar.markdown(f"- {doc_name}")
707
- doc_names.append(doc_name)
708
- doc_ids.append(doc_id)
709
  else:
710
  st.sidebar.write("No saved documents found.")
711
  except Exception as e:
712
  st.sidebar.error(f"Error fetching documents: {e}")
 
713
 
714
- st.sidebar.markdown('</div>', unsafe_allow_html=True)
715
-
716
- # Below saved documents: Upload and Delete buttons
717
  st.sidebar.markdown('<div class="button-container">', unsafe_allow_html=True)
718
 
719
- # File uploader
720
  uploaded_file = st.sidebar.file_uploader("", key="file_uploader", label_visibility="collapsed")
721
-
722
- # Upload button
723
  if st.sidebar.button("Upload", key="upload_button"):
724
  if uploaded_file:
725
- upload_to_firebase(st.session_state["wix_user_id"], uploaded_file)
726
- st.sidebar.success(f"Document '{uploaded_file.name}' uploaded successfully.")
 
 
 
727
  else:
728
  st.sidebar.warning("Please select a file to upload.")
729
 
730
- # Delete Selected Button
731
  if docs:
732
- selected_docs = st.sidebar.multiselect("Select documents to delete", options=doc_names)
 
733
  if st.sidebar.button("Delete Selected", key="delete_button"):
734
- for doc_name in selected_docs:
735
- # Find the doc_id corresponding to the doc_name
736
- doc_id_to_delete = None
737
- for doc_id, doc_data in docs.items():
738
- if doc_data.get('content', '') == doc_name:
739
- doc_id_to_delete = doc_id
740
- break
741
- if doc_id_to_delete:
742
- delete_document(st.session_state["wix_user_id"], doc_id_to_delete)
743
- st.sidebar.success("Selected documents deleted.")
744
- else:
745
- st.sidebar.write("No documents to delete.")
746
-
747
- st.sidebar.markdown('</div>', unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
748
 
749
 
750
  # Show Trust Builders Section
 
672
 
673
 
674
  st.sidebar.header("TrustVault®")
675
+ st.sidebar.subheader("Saved Documents")
676
+
677
  st.sidebar.markdown("""
678
  <style>
679
  .scrollable-container {
 
688
  .button-container {
689
  display: flex;
690
  justify-content: space-between;
 
691
  }
692
  </style>
693
  """, unsafe_allow_html=True)
694
 
695
+ # Scrollable container for saved documents
 
696
  st.sidebar.markdown('<div class="scrollable-container">', unsafe_allow_html=True)
 
697
  try:
698
  # Fetch and display saved documents
699
  docs = db.child("users").child(st.session_state["wix_user_id"]).child("KnowledgeBase").get().val()
 
 
700
  if docs:
701
  for doc_id, doc_data in docs.items():
702
+ doc_name = doc_data.get("content", "Document")
703
  st.sidebar.markdown(f"- {doc_name}")
 
 
704
  else:
705
  st.sidebar.write("No saved documents found.")
706
  except Exception as e:
707
  st.sidebar.error(f"Error fetching documents: {e}")
708
+ st.sidebar.markdown("</div>", unsafe_allow_html=True)
709
 
710
+ # Button container for Upload and Delete actions
 
 
711
  st.sidebar.markdown('<div class="button-container">', unsafe_allow_html=True)
712
 
713
+ # File uploader button
714
  uploaded_file = st.sidebar.file_uploader("", key="file_uploader", label_visibility="collapsed")
 
 
715
  if st.sidebar.button("Upload", key="upload_button"):
716
  if uploaded_file:
717
+ try:
718
+ upload_to_firebase(st.session_state["wix_user_id"], uploaded_file)
719
+ st.sidebar.success(f"Document '{uploaded_file.name}' uploaded successfully!")
720
+ except Exception as e:
721
+ st.sidebar.error(f"Error uploading document: {e}")
722
  else:
723
  st.sidebar.warning("Please select a file to upload.")
724
 
725
+ # Delete selected documents
726
  if docs:
727
+ delete_options = [doc_data.get("content", "Document") for doc_id, doc_data in docs.items()]
728
+ selected_docs = st.sidebar.multiselect("Delete documents", options=delete_options, key="delete_docs")
729
  if st.sidebar.button("Delete Selected", key="delete_button"):
730
+ try:
731
+ for doc_name in selected_docs:
732
+ for doc_id, doc_data in docs.items():
733
+ if doc_data.get("content") == doc_name:
734
+ delete_document(st.session_state["wix_user_id"], doc_id)
735
+ st.sidebar.success("Selected documents deleted successfully!")
736
+ st.experimental_rerun()
737
+ except Exception as e:
738
+ st.sidebar.error(f"Error deleting documents: {e}")
739
+ st.sidebar.markdown("</div>", unsafe_allow_html=True)
740
+
741
+
742
+
743
+
744
+
745
+
746
+
747
+
748
+
749
+
750
+
751
+
752
+
753
+
754
+
755
+
756
+
757
+
758
+
759
+
760
+
761
 
762
 
763
  # Show Trust Builders Section