Wajahat698 commited on
Commit
1cfe85d
·
verified ·
1 Parent(s): d924165

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -36
app.py CHANGED
@@ -683,11 +683,9 @@ def side():
683
 
684
 
685
 
686
- st.sidebar.header("TrustVault®")
687
- st.sidebar.subheader("Saved Documents")
688
-
689
- # CSS for styling
690
- st.sidebar.markdown("""
691
  <style>
692
  .scrollable-container {
693
  max-height: 200px;
@@ -701,67 +699,69 @@ def side():
701
  .button-container {
702
  display: flex;
703
  justify-content: space-between;
 
704
  }
705
  </style>
706
  """, unsafe_allow_html=True)
707
 
708
- st.sidebar.markdown('<div class="scrollable-container">', unsafe_allow_html=True)
 
709
 
 
 
710
  try:
711
- # Fetch and display saved documents
712
  docs = db.child("users").child(st.session_state["wix_user_id"]).child("KnowledgeBase").get().val()
713
  if docs:
714
  for doc_id, doc_data in docs.items():
715
  doc_name = doc_data.get("content", f"Document {doc_id[:8]}")
716
- st.sidebar.markdown(f"- {doc_name}")
717
  else:
718
- st.sidebar.write("No saved documents found.")
719
  except Exception as e:
720
- st.sidebar.error(f"Error fetching documents: {e}")
 
 
721
 
722
- st.sidebar.markdown("</div>", unsafe_allow_html=True)
 
723
 
724
- # File uploader and delete actions container
725
- st.sidebar.markdown('<div class="button-container">', unsafe_allow_html=True)
726
 
727
- # File uploader button
728
- uploaded_file = st.sidebar.file_uploader("", key="file_uploader", label_visibility="collapsed")
729
- if st.sidebar.button("Upload", key="upload_button"):
730
  if uploaded_file:
731
  try:
732
  # Convert and upload the file
733
  file_content = convert_file_to_md(uploaded_file)
734
  if file_content:
735
  doc_id = str(uuid.uuid4())
736
- db.child("users").child(st.session_state["wix_user_id"]).child("KnowledgeBase").child(doc_id).set({
737
- "content": file_content
738
- })
739
- st.sidebar.success(f"Document '{uploaded_file.name}' uploaded successfully!")
740
- st.rerun() # Refresh the page after uploading
741
  else:
742
- st.sidebar.warning("Failed to process the uploaded file.")
743
  except Exception as e:
744
- st.sidebar.error(f"Error uploading document: {e}")
745
  else:
746
- st.sidebar.warning("Please select a file to upload.")
747
 
748
- # Delete selected documents
749
- try:
750
- if docs:
751
- delete_options = [doc_data.get("content", f"Document {doc_id[:8]}") for doc_id, doc_data in docs.items()]
752
- selected_docs = st.sidebar.multiselect("Delete documents", options=delete_options, key="delete_docs")
753
- if st.sidebar.button("Delete Selected", key="delete_button"):
754
  for doc_name in selected_docs:
755
- # Find the doc_id to delete
756
  for doc_id, doc_data in docs.items():
757
  if doc_data.get("content") == doc_name:
758
  db.child("users").child(st.session_state["wix_user_id"]).child("KnowledgeBase").child(doc_id).remove()
759
- st.sidebar.success("Selected documents deleted successfully!")
760
- st.rerun() # Refresh the page after deletion
761
- except Exception as e:
762
- st.sidebar.error(f"Error deleting documents: {e}")
763
 
764
- st.sidebar.markdown("</div>", unsafe_allow_html=True)
765
 
766
 
767
 
 
683
 
684
 
685
 
686
+ st.header("TrustVault®")
687
+ st.subheader("Saved Documents")
688
+ st.markdown("""
 
 
689
  <style>
690
  .scrollable-container {
691
  max-height: 200px;
 
699
  .button-container {
700
  display: flex;
701
  justify-content: space-between;
702
+ margin-top: 10px;
703
  }
704
  </style>
705
  """, unsafe_allow_html=True)
706
 
707
+ # Saved Documents Section
708
+ st.subheader("Saved Documents")
709
 
710
+ # Text area for displaying saved documents
711
+ doc_texts = ""
712
  try:
 
713
  docs = db.child("users").child(st.session_state["wix_user_id"]).child("KnowledgeBase").get().val()
714
  if docs:
715
  for doc_id, doc_data in docs.items():
716
  doc_name = doc_data.get("content", f"Document {doc_id[:8]}")
717
+ doc_texts += f"{doc_name}\n"
718
  else:
719
+ doc_texts = "No saved documents found."
720
  except Exception as e:
721
+ st.error(f"Error fetching documents: {e}")
722
+
723
+ savedDoc = st.text_area("", doc_texts, height=200)
724
 
725
+ # Button container for Upload and Delete actions
726
+ st.markdown('<div class="button-container">', unsafe_allow_html=True)
727
 
728
+ # File uploader
729
+ uploaded_file = st.file_uploader("", key="file_uploader", label_visibility="collapsed")
730
 
731
+ # Upload button
732
+ if st.button("Upload", key="upload_button"):
 
733
  if uploaded_file:
734
  try:
735
  # Convert and upload the file
736
  file_content = convert_file_to_md(uploaded_file)
737
  if file_content:
738
  doc_id = str(uuid.uuid4())
739
+ db.child("users").child(st.session_state["wix_user_id"]).child("KnowledgeBase").child(doc_id).set({"content": file_content})
740
+ st.success(f"Document uploaded successfully!")
741
+ st.rerun() # Refresh the display
 
 
742
  else:
743
+ st.warning("Failed to process the uploaded file.")
744
  except Exception as e:
745
+ st.error(f"Error uploading document: {e}")
746
  else:
747
+ st.warning("Please select a file to upload.")
748
 
749
+ # Delete selected documents logic
750
+ if docs:
751
+ delete_options = [doc_data.get("content", f"Document {doc_id[:8]}") for doc_id, doc_data in docs.items()]
752
+ selected_docs = st.multiselect("Select documents to delete", options=delete_options)
753
+ if st.button("Delete Selected", key="delete_button"):
754
+ try:
755
  for doc_name in selected_docs:
 
756
  for doc_id, doc_data in docs.items():
757
  if doc_data.get("content") == doc_name:
758
  db.child("users").child(st.session_state["wix_user_id"]).child("KnowledgeBase").child(doc_id).remove()
759
+ st.success("Selected documents deleted successfully!")
760
+ st.rerub() # Refresh the display
761
+ except Exception as e:
762
+ st.sidebar.error(f"Error deleting documents: {e}")
763
 
764
+ st.markdown('</div>', unsafe_allow_html=True)
765
 
766
 
767