Wajahat698 commited on
Commit
eea7cee
·
verified ·
1 Parent(s): 310d230

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -56
app.py CHANGED
@@ -683,6 +683,9 @@ def side():
683
 
684
 
685
  st.header("TrustVault®")
 
 
 
686
  st.sidebar.markdown("""
687
  <style>
688
  .scrollable-container {
@@ -697,30 +700,39 @@ def side():
697
  .button-container {
698
  display: flex;
699
  justify-content: space-between;
700
- margin-top: 10px;
701
  }
702
  .custom-upload-button {
703
  display: inline-block;
704
  font-size: 14px;
705
- font-weight: 600;
706
  color: white;
707
  background-color: #007bff;
708
  padding: 8px 16px;
709
  border-radius: 5px;
710
  cursor: pointer;
711
  text-align: center;
712
- margin-right: 10px;
713
  }
714
  .custom-upload-button:hover {
715
  background-color: #0056b3;
716
  }
717
- .hidden-file-uploader {
718
- display: none;
 
 
 
 
 
 
 
 
 
 
719
  }
720
  </style>
721
  """, unsafe_allow_html=True)
722
-
723
- # Saved Documents Section
724
  if "documents" not in st.session_state:
725
  try:
726
  docs = db.child("users").child(st.session_state["wix_user_id"]).child("KnowledgeBase").get().val()
@@ -728,9 +740,8 @@ def side():
728
  except Exception as e:
729
  st.sidebar.error(f"Error fetching documents: {e}")
730
  st.session_state["documents"] = {}
731
-
732
- st.sidebar.subheader("Saved Documents")
733
-
734
  saved_docs = ""
735
  if st.session_state["documents"]:
736
  for doc_id, doc_data in st.session_state["documents"].items():
@@ -738,63 +749,46 @@ def side():
738
  saved_docs += f"{doc_name}\n"
739
  else:
740
  saved_docs = "Save documents like your brand tonality, key phrases, or segments here and they will show here."
741
-
742
- # Display documents inside a text area (scrollable)
743
  saved_docs_display = st.sidebar.text_area(
744
  label="",
745
  value=saved_docs,
746
  height=150,
747
  key="saved_documents_text_area",
748
- disabled=True # To prevent editing of the text area
749
  )
750
-
751
- # Upload and Delete Buttons
752
  st.sidebar.markdown('<div class="button-container">', unsafe_allow_html=True)
753
-
754
- # Custom File Upload Button
755
- uploaded_file = st.file_uploader("", key="hidden_file_uploader", label_visibility="collapsed")
756
  upload_button_html = f"""
757
- <label for="hidden_file_uploader" class="custom-upload-button">Upload</label>
758
  """
759
  st.sidebar.markdown(upload_button_html, unsafe_allow_html=True)
760
-
761
- if uploaded_file:
762
- try:
763
- file_content = convert_file_to_md(uploaded_file)
764
- if file_content:
765
- doc_id = str(uuid.uuid4())
766
- db.child("users").child(st.session_state["wix_user_id"]).child("KnowledgeBase").child(doc_id).set(
767
- {"content": file_content}
768
- )
769
- st.session_state["documents"][doc_id] = {"content": file_content}
770
- st.sidebar.success(f"Document '{uploaded_file.name}' uploaded successfully!")
771
- st.experimental_rerun()
772
- else:
773
- st.sidebar.warning("Failed to process the uploaded file.")
774
- except Exception as e:
775
- st.sidebar.error(f"Error uploading document: {e}")
776
-
777
- # Delete Button and Selector
778
  if st.session_state["documents"]:
779
- with st.sidebar:
780
- selected_doc_to_delete = st.selectbox(
781
- "Select document to delete",
782
- options=list(st.session_state["documents"].keys()),
783
- format_func=lambda x: st.session_state["documents"][x].get("content", f"Document {x}"),
784
- key="delete_doc_selector"
785
- )
786
- if st.button("Delete", key="delete_button"):
787
- try:
788
- db.child("users").child(st.session_state["wix_user_id"]).child("KnowledgeBase").child(selected_doc_to_delete).remove()
789
- st.session_state["documents"].pop(selected_doc_to_delete)
790
- st.sidebar.success("Document deleted successfully!")
791
- st.experimental_rerun()
792
- except Exception as e:
793
- st.sidebar.error(f"Error deleting document: {e}")
794
-
795
- st.sidebar.markdown('</div>', unsafe_allow_html=True)
796
-
797
-
798
 
799
 
800
 
 
683
 
684
 
685
  st.header("TrustVault®")
686
+ st.sidebar.subheader("Saved Documents")
687
+
688
+ # Add custom styles for buttons and scrollable container
689
  st.sidebar.markdown("""
690
  <style>
691
  .scrollable-container {
 
700
  .button-container {
701
  display: flex;
702
  justify-content: space-between;
 
703
  }
704
  .custom-upload-button {
705
  display: inline-block;
706
  font-size: 14px;
707
+ font-weight: bold;
708
  color: white;
709
  background-color: #007bff;
710
  padding: 8px 16px;
711
  border-radius: 5px;
712
  cursor: pointer;
713
  text-align: center;
714
+ border: none;
715
  }
716
  .custom-upload-button:hover {
717
  background-color: #0056b3;
718
  }
719
+ .custom-delete-button {
720
+ background-color: #dc3545;
721
+ color: white;
722
+ padding: 8px 16px;
723
+ font-size: 14px;
724
+ border: none;
725
+ border-radius: 5px;
726
+ cursor: pointer;
727
+ font-weight: bold;
728
+ }
729
+ .custom-delete-button:hover {
730
+ background-color: #a71d2a;
731
  }
732
  </style>
733
  """, unsafe_allow_html=True)
734
+
735
+ # Fetch documents from Firebase
736
  if "documents" not in st.session_state:
737
  try:
738
  docs = db.child("users").child(st.session_state["wix_user_id"]).child("KnowledgeBase").get().val()
 
740
  except Exception as e:
741
  st.sidebar.error(f"Error fetching documents: {e}")
742
  st.session_state["documents"] = {}
743
+
744
+ # Display saved documents
 
745
  saved_docs = ""
746
  if st.session_state["documents"]:
747
  for doc_id, doc_data in st.session_state["documents"].items():
 
749
  saved_docs += f"{doc_name}\n"
750
  else:
751
  saved_docs = "Save documents like your brand tonality, key phrases, or segments here and they will show here."
752
+
753
+ # Scrollable text area
754
  saved_docs_display = st.sidebar.text_area(
755
  label="",
756
  value=saved_docs,
757
  height=150,
758
  key="saved_documents_text_area",
759
+ disabled=True
760
  )
761
+
762
+ # File uploader and delete button in the same row
763
  st.sidebar.markdown('<div class="button-container">', unsafe_allow_html=True)
764
+
765
+ # File uploader button (customized)
766
+ uploaded_file = st.file_uploader("", type=["pdf", "docx", "txt"], key="hidden_file_uploader", label_visibility="collapsed")
767
  upload_button_html = f"""
768
+ <button class="custom-upload-button" onclick="document.querySelector('input[type=file]').click();">Upload</button>
769
  """
770
  st.sidebar.markdown(upload_button_html, unsafe_allow_html=True)
771
+
772
+ # Delete Button
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
773
  if st.session_state["documents"]:
774
+ selected_doc_to_delete = st.selectbox(
775
+ "Select document to delete",
776
+ options=list(st.session_state["documents"].keys()),
777
+ format_func=lambda x: st.session_state["documents"][x].get("content", f"Document {x}"),
778
+ key="delete_doc_selector"
779
+ )
780
+ if st.sidebar.button("Delete", key="delete_button"):
781
+ try:
782
+ delete_document(st.session_state["wix_user_id"], selected_doc_to_delete)
783
+ st.session_state["documents"].pop(selected_doc_to_delete)
784
+ st.rerun()
785
+ except Exception as e:
786
+ st.sidebar.error(f"Error deleting document: {e}")
787
+
788
+ st.sidebar.markdown("</div>", unsafe_allow_html=True)
789
+
790
+
791
+
 
792
 
793
 
794