Wajahat698 commited on
Commit
b1b7005
·
verified ·
1 Parent(s): e7cc306

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -52
app.py CHANGED
@@ -712,68 +712,62 @@ def side():
712
  st.session_state["documents"] = {}
713
 
714
  st.sidebar.subheader("Saved Documents")
 
715
  saved_docs = ""
716
  if st.session_state["documents"]:
717
  for doc_id, doc_data in st.session_state["documents"].items():
718
  doc_name = doc_data.get("content", f"Document {doc_id[:8]}")
719
- saved_docs += f"- {doc_name}\n"
720
  else:
721
  saved_docs = "Save documents like your brand tonality, key phrases, or segments here and they will show here."
722
- # Scrollable text area
723
- st.sidebar.markdown(
724
- f"""
725
- <style>
726
- .scrollable-text-area {{
727
- max-height: 150px;
728
- overflow-y: auto;
729
- border: 1px solid gray;
730
- border-radius: 5px;
731
- background-color: #f9f9f9;
732
- padding: 10px;
733
- font-size: 14px;
734
- color: #555;
735
- }}
736
- </style>
737
- <div class="scrollable-text-area">{saved_docs}</div>
738
- """,
739
- unsafe_allow_html=True,)
740
 
741
  # File uploader and delete buttons
742
- uploaded_file = st.sidebar.file_uploader("", key="file_uploader", label_visibility="collapsed")
743
- if st.sidebar.button("Upload", key="upload_button"):
744
- if uploaded_file:
745
- try:
746
- file_content = convert_file_to_md(uploaded_file)
747
- if file_content:
748
- doc_id = str(uuid.uuid4())
749
- db.child("users").child(st.session_state["wix_user_id"]).child("KnowledgeBase").child(doc_id).set(
750
- {"content": file_content}
751
- )
752
- st.session_state["documents"][doc_id] = {"content": file_content}
753
- st.sidebar.success(f"Document '{uploaded_file.name}' uploaded successfully!")
754
- st.rerun()
755
- else:
756
- st.sidebar.warning("Failed to process the uploaded file.")
757
- except Exception as e:
758
- st.sidebar.error(f"Error uploading document: {e}")
759
 
760
- # Delete documents functionality
761
- if st.session_state["documents"]:
762
- selected_doc_to_delete = st.sidebar.selectbox(
763
- "Select document to delete",
764
- options=list(st.session_state["documents"].keys()),
765
- format_func=lambda x: st.session_state["documents"][x].get("content", f"Document {x}")
766
- )
767
- if st.sidebar.button("Delete", key="delete_button"):
768
- try:
769
- db.child("users").child(st.session_state["wix_user_id"]).child("KnowledgeBase").child(selected_doc_to_delete).remove()
770
- st.session_state["documents"].pop(selected_doc_to_delete)
771
- st.sidebar.success("Document deleted successfully!")
772
- st.rerun()
773
- except Exception as e:
774
- st.sidebar.error(f"Error deleting document: {e}")
 
 
 
775
 
776
- st.sidebar.markdown('</div>', unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
777
 
778
  # Show Trust Builders Section
779
  st.subheader("Show My TrustBuilders®")
 
712
  st.session_state["documents"] = {}
713
 
714
  st.sidebar.subheader("Saved Documents")
715
+
716
  saved_docs = ""
717
  if st.session_state["documents"]:
718
  for doc_id, doc_data in st.session_state["documents"].items():
719
  doc_name = doc_data.get("content", f"Document {doc_id[:8]}")
720
+ saved_docs += f"{doc_name}\n"
721
  else:
722
  saved_docs = "Save documents like your brand tonality, key phrases, or segments here and they will show here."
723
+
724
+ # Display documents inside a text area (scrollable)
725
+ saved_docs_display = st.sidebar.text_area(
726
+ label="",
727
+ value=saved_docs,
728
+ height=150,
729
+ key="saved_documents_text_area",
730
+ disabled=True # To prevent editing of the text area
731
+ )
 
 
 
 
 
 
 
 
 
732
 
733
  # File uploader and delete buttons
734
+ col1, col2 = st.sidebar.columns(2, gap="small")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
735
 
736
+ with col1:
737
+ uploaded_file = st.file_uploader("", key="file_uploader", label_visibility="collapsed")
738
+ if st.button("Upload", key="upload_button"):
739
+ if uploaded_file:
740
+ try:
741
+ file_content = convert_file_to_md(uploaded_file)
742
+ if file_content:
743
+ doc_id = str(uuid.uuid4())
744
+ db.child("users").child(st.session_state["wix_user_id"]).child("KnowledgeBase").child(doc_id).set(
745
+ {"content": file_content}
746
+ )
747
+ st.session_state["documents"][doc_id] = {"content": file_content}
748
+ st.sidebar.success(f"Document '{uploaded_file.name}' uploaded successfully!")
749
+ st.experimental_rerun()
750
+ else:
751
+ st.sidebar.warning("Failed to process the uploaded file.")
752
+ except Exception as e:
753
+ st.sidebar.error(f"Error uploading document: {e}")
754
 
755
+ with col2:
756
+ if st.session_state["documents"]:
757
+ selected_doc_to_delete = st.selectbox(
758
+ "Select document to delete",
759
+ options=list(st.session_state["documents"].keys()),
760
+ format_func=lambda x: st.session_state["documents"][x].get("content", f"Document {x}"),
761
+ key="delete_doc_selector"
762
+ )
763
+ if st.button("Delete", key="delete_button"):
764
+ try:
765
+ db.child("users").child(st.session_state["wix_user_id"]).child("KnowledgeBase").child(selected_doc_to_delete).remove()
766
+ st.session_state["documents"].pop(selected_doc_to_delete)
767
+ st.sidebar.success("Document deleted successfully!")
768
+ st.experimental_rerun()
769
+ except Exception as e:
770
+ st.sidebar.error(f"Error deleting document: {e}")
771
 
772
  # Show Trust Builders Section
773
  st.subheader("Show My TrustBuilders®")