Wajahat698 commited on
Commit
87d069f
·
verified ·
1 Parent(s): 9b673c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -123
app.py CHANGED
@@ -432,13 +432,6 @@ def update_message_counter():
432
 
433
 
434
 
435
- def delete_trustbuilder(user_id, trustbuilder_id):
436
- try:
437
- db.child("users").child(user_id).child("TrustBuilder").child(trustbuilder_id).remove()
438
- st.success("TrustBuilder deleted successfully.")
439
- st.experimental_rerun() # Refresh the app to reflect deletion
440
- except Exception as e:
441
- st.error(f"Error deleting TrustBuilder: {e}")
442
 
443
  def store_brand_tonality(user_id, message):
444
  try:
@@ -548,14 +541,6 @@ def delete_document(user_id, doc_id):
548
  except Exception as e:
549
  st.error(f"Error deleting document: {e}")
550
 
551
- # Fetch documents from Firebase
552
- def delete_document(user_id, doc_id):
553
- try:
554
- db.child("users").child(user_id).child("documents").child(doc_id).remove()
555
- st.success("Document deleted successfully.")
556
- st.experimental_rerun()
557
- except Exception as e:
558
- st.error(f"Error deleting document: {e}")
559
 
560
 
561
  def side():
@@ -687,44 +672,8 @@ def side():
687
 
688
 
689
  st.sidebar.header("TrustVault®")
690
- image_files = [
691
- ("Bucket_STABILITY.png"),
692
- ("Bucket_DEVELOPMENT.png"),
693
- ("Bucket_RELATIONSHIP.png"),
694
- ("Bucket_BENEFIT.png"),
695
- ("Bucket_VISION.png"),
696
- ("Bucket_COMPETENCE.png"),
697
- ]
698
-
699
- # CSS for Layout and Hover Effect
700
- st.markdown(
701
- """
702
- <style>
703
- .image-container {
704
- display: flex;
705
- justify-content: center;
706
- gap: 20px;
707
- }
708
- .image-wrapper {
709
- text-align: center;
710
- }
711
- .image-wrapper img {
712
- width: 80px;
713
- height: 80px;
714
- object-fit: contain;
715
- cursor: pointer;
716
- transition: transform 0.3s;
717
- }
718
- .image-wrapper img:hover {
719
- transform: scale(1.1);
720
- }
721
- </style>
722
- """,
723
- unsafe_allow_html=True,
724
- )
725
-
726
-
727
- # CSS for scrollable container
728
  st.markdown("""
729
  <style>
730
  .scrollable-container {
@@ -737,91 +686,72 @@ def side():
737
  }
738
  </style>
739
  """, unsafe_allow_html=True)
740
-
741
- # Saved Documents Section
742
- with st.container():
743
- st.subheader("Saved Documents")
744
- st.write("Save documents like your brand tonality, key phrases, or segments here.")
745
- st.markdown('<div class="scrollable-container">', unsafe_allow_html=True)
746
-
747
- # Replace with your document fetching logic
748
- docs = {} # Example: fetch_documents(st.session_state["user_id"])
749
-
750
  if docs:
751
  for doc_id, doc_data in docs.items():
752
- st.markdown(f"**Document ID:** {doc_id[:8]}")
753
- st.text_area("Preview", doc_data.get("content", ""), height=80, disabled=True)
754
- public_url = doc_data.get("public_url", "URL not available")
755
- if public_url != "URL not available":
756
- st.markdown(f"[View Full Document]({public_url})", unsafe_allow_html=True)
 
757
  else:
758
  st.write("No saved documents found.")
759
-
760
- st.markdown('</div>', unsafe_allow_html=True)
761
-
 
 
762
  # File Upload Section
763
  st.subheader("Upload New Documents")
764
- with st.form(key='upload_form'):
765
- uploaded_files = st.file_uploader(
766
- "Select PDF, DOCX, or TXT files to upload",
767
- type=["pdf", "docx", "txt"],
768
- accept_multiple_files=True
769
- )
770
- submit_upload = st.form_submit_button(label='Upload')
771
-
772
- if submit_upload:
773
- if uploaded_files:
774
- for file in uploaded_files:
775
- # Add your file upload logic here
776
- st.success(f"File {file.name} uploaded successfully!")
777
- else:
778
- st.warning("Please select at least one file to upload.")
779
-
780
-
781
 
782
-
783
  st.subheader("Show My TrustBuilders®")
784
- search_query = st.text_input("Search by keyword", key="search_query")
785
-
786
- # Dropdown for selecting Trust Bucket
787
  trust_buckets = ["Stability", "Development", "Relationship", "Benefit", "Vision", "Competence"]
788
- selected_bucket = st.selectbox("Select Trust Bucket", trust_buckets, key="selected_bucket")
789
 
790
- if st.button("Show", key="show_button"):
791
  st.write(f"Filtering TrustBuilders for keyword='{search_query}' and bucket='{selected_bucket}'")
792
- try:
793
- # Fetch TrustBuilders
794
- trustbuilders = fetch_trustbuilders("user_id_placeholder")
795
- results = []
796
- for bucket, contents in trustbuilders.items():
797
- if selected_bucket == "All" or selected_bucket == bucket:
798
- for content in contents:
799
- if not search_query or search_query.lower() in content.lower():
800
- results.append(f"{bucket}: {content}")
801
- if results:
802
- for result in results:
803
- st.markdown(f"- {result}")
804
- else:
805
- st.write("No TrustBuilders found.")
806
- except Exception as e:
807
- st.error(f"Error fetching TrustBuilders: {e}")
808
 
809
-
810
- # Save TrustBuilders Section
811
  st.subheader("Save TrustBuilders®")
812
- brand = st.text_input("Brand/Product/Person", key="brand_input_save")
813
- trust_builder_text = st.text_area("Type/paste Trust Builder®", key="trust_builder_text_save", height=100)
 
814
 
815
- # Dropdown for selecting Trust Bucket to save into
816
- selected_save_bucket = st.selectbox("Choose Trust Bucket to Save", trust_buckets[1:], key="save_bucket")
817
-
818
- # Save button
819
- if st.button("Save TrustBuilder", key="save_button"):
820
- if selected_save_bucket and trust_builder_text.strip():
821
- save_trustbuilder("user_id_placeholder", trust_builder_text.strip(), selected_save_bucket)
822
  else:
823
- st.warning("Please fill in all fields before saving.")
824
-
825
 
826
 
827
 
 
432
 
433
 
434
 
 
 
 
 
 
 
 
435
 
436
  def store_brand_tonality(user_id, message):
437
  try:
 
541
  except Exception as e:
542
  st.error(f"Error deleting document: {e}")
543
 
 
 
 
 
 
 
 
 
544
 
545
 
546
  def side():
 
672
 
673
 
674
  st.sidebar.header("TrustVault®")
675
+
676
+ st.subheader("Saved Documents")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
677
  st.markdown("""
678
  <style>
679
  .scrollable-container {
 
686
  }
687
  </style>
688
  """, unsafe_allow_html=True)
689
+ st.markdown('<div class="scrollable-container">', unsafe_allow_html=True)
690
+
691
+ # Fetch and display saved documents
692
+ try:
693
+ docs = db.child("users").child(user_id).child("KnowledgeBase").get().val()
 
 
 
 
 
694
  if docs:
695
  for doc_id, doc_data in docs.items():
696
+ col1, col2 = st.columns([4, 1])
697
+ with col1:
698
+ st.write(doc_data.get("content", ""))
699
+ with col2:
700
+ if st.button("Delete", key=f"delete_{doc_id}"):
701
+ delete_document(user_id, doc_id)
702
  else:
703
  st.write("No saved documents found.")
704
+ except Exception as e:
705
+ st.error(f"Error fetching documents: {e}")
706
+
707
+ st.markdown('</div>', unsafe_allow_html=True)
708
+
709
  # File Upload Section
710
  st.subheader("Upload New Documents")
711
+ uploaded_file = st.file_uploader("Choose a file to upload (PDF, DOCX, TXT):", type=["pdf", "docx", "txt"])
712
+ if uploaded_file:
713
+ if st.button("Upload"):
714
+ try:
715
+ doc_id = str(uuid.uuid4())
716
+ db.child("users").child(user_id).child("KnowledgeBase").child(doc_id).set({
717
+ "content": uploaded_file.name
718
+ })
719
+ st.success(f"File '{uploaded_file.name}' uploaded successfully!")
720
+ except Exception as e:
721
+ st.error(f"Error uploading file: {e}")
 
 
 
 
 
 
722
 
723
+ # Show Trust Builders Section
724
  st.subheader("Show My TrustBuilders®")
725
+ search_query = st.text_input("Search by keyword")
 
 
726
  trust_buckets = ["Stability", "Development", "Relationship", "Benefit", "Vision", "Competence"]
727
+ selected_bucket = st.selectbox("Select Trust Bucket", trust_buckets)
728
 
729
+ if st.button("Show"):
730
  st.write(f"Filtering TrustBuilders for keyword='{search_query}' and bucket='{selected_bucket}'")
731
+ trustbuilders = fetch_trustbuilders(user_id)
732
+ results = []
733
+ for trustbuilder_id, data in trustbuilders.items():
734
+ content = data.get("content", "")
735
+ bucket = data.get("bucket", "")
736
+ if (selected_bucket == bucket or not selected_bucket) and (not search_query or search_query.lower() in content.lower()):
737
+ results.append(f"{bucket}: {content}")
738
+ if results:
739
+ for result in results:
740
+ st.markdown(f"- {result}")
741
+ else:
742
+ st.write("No TrustBuilders found.")
 
 
 
 
743
 
744
+ # Save Trust Builders Section
 
745
  st.subheader("Save TrustBuilders®")
746
+ brand = st.text_input("Brand/Product/Person", key="brand_input")
747
+ trust_builder_text = st.text_area("Type/paste Trust Builder®")
748
+ selected_save_bucket = st.selectbox("Choose Trust Bucket to Save", trust_buckets, key="save_bucket")
749
 
750
+ if st.button("Save"):
751
+ if trust_builder_text.strip() and selected_save_bucket:
752
+ save_trustbuilder(user_id, trust_builder_text.strip(), selected_save_bucket)
 
 
 
 
753
  else:
754
+ st.warning("Please fill all fields before saving.")
 
755
 
756
 
757