Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -166,46 +166,13 @@ def upload_to_firebase(user_id, content):
|
|
| 166 |
return None
|
| 167 |
|
| 168 |
|
| 169 |
-
def fetch_trustbuilders(user_id
|
| 170 |
try:
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
st.write("TrustBuilders retrieved from Firebase:", trustbuilders)
|
| 174 |
-
|
| 175 |
-
if not trustbuilders:
|
| 176 |
-
st.write("No TrustBuilders found in Firebase.")
|
| 177 |
-
return {}
|
| 178 |
-
|
| 179 |
-
filtered_trustbuilders = {}
|
| 180 |
-
for key, value in trustbuilders.items():
|
| 181 |
-
message = value.get("message", "").lower()
|
| 182 |
-
brand_field = value.get("brand", "").lower()
|
| 183 |
-
bucket_field = value.get("bucket", "")
|
| 184 |
-
|
| 185 |
-
st.write(f"Checking TrustBuilder {key}:")
|
| 186 |
-
st.write(f" Message: {message}")
|
| 187 |
-
st.write(f" Brand: {brand_field}")
|
| 188 |
-
st.write(f" Bucket: {bucket_field}")
|
| 189 |
-
|
| 190 |
-
if keyword and keyword.lower() not in message:
|
| 191 |
-
st.write(" Keyword does not match.")
|
| 192 |
-
continue
|
| 193 |
-
if brand and brand.lower() not in brand_field:
|
| 194 |
-
st.write(" Brand does not match.")
|
| 195 |
-
continue
|
| 196 |
-
if bucket and bucket != "All" and bucket != bucket_field:
|
| 197 |
-
st.write(f" Bucket '{bucket_field}' does not match selected '{bucket}'.")
|
| 198 |
-
continue
|
| 199 |
-
|
| 200 |
-
st.write(" TrustBuilder matches filters.")
|
| 201 |
-
filtered_trustbuilders[key] = value
|
| 202 |
-
|
| 203 |
-
st.write("Filtered TrustBuilders:", filtered_trustbuilders)
|
| 204 |
-
return filtered_trustbuilders
|
| 205 |
except Exception as e:
|
| 206 |
st.error(f"Error fetching TrustBuilders: {e}")
|
| 207 |
return {}
|
| 208 |
-
|
| 209 |
|
| 210 |
def delete_trustbuilder(user_id, trustbuilder_id):
|
| 211 |
try:
|
|
@@ -456,48 +423,6 @@ def update_message_counter():
|
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
-
def fetch_trustbuilders(user_id, keyword=None, brand=None, bucket=None):
|
| 460 |
-
try:
|
| 461 |
-
st.write(f"Fetching TrustBuilders with keyword='{keyword}', brand='{brand}', bucket='{bucket}'")
|
| 462 |
-
trustbuilders = db.child("users").child(user_id).child("TrustBuilder").get().val()
|
| 463 |
-
st.write("TrustBuilders retrieved from Firebase:", trustbuilders)
|
| 464 |
-
|
| 465 |
-
if not trustbuilders:
|
| 466 |
-
st.write("No TrustBuilders found in Firebase.")
|
| 467 |
-
return {}
|
| 468 |
-
|
| 469 |
-
# Apply filters to the retrieved TrustBuilders
|
| 470 |
-
filtered_trustbuilders = {}
|
| 471 |
-
for key, value in trustbuilders.items():
|
| 472 |
-
message = value.get("message", "").lower()
|
| 473 |
-
brand_field = value.get("brand", "").lower()
|
| 474 |
-
bucket_field = value.get("bucket", "")
|
| 475 |
-
|
| 476 |
-
st.write(f"Checking TrustBuilder {key}:")
|
| 477 |
-
st.write(f" Message: {message}")
|
| 478 |
-
st.write(f" Brand: {brand_field}")
|
| 479 |
-
st.write(f" Bucket: {bucket_field}")
|
| 480 |
-
|
| 481 |
-
# Apply filtering conditions
|
| 482 |
-
if keyword and keyword.lower() not in message:
|
| 483 |
-
st.write(" Keyword does not match.")
|
| 484 |
-
continue
|
| 485 |
-
if brand and brand.lower() not in brand_field:
|
| 486 |
-
st.write(" Brand does not match.")
|
| 487 |
-
continue
|
| 488 |
-
if bucket and bucket != "All" and bucket != bucket_field:
|
| 489 |
-
st.write(f" Bucket '{bucket_field}' does not match selected '{bucket}'.")
|
| 490 |
-
continue
|
| 491 |
-
|
| 492 |
-
# If all filters match, add to results
|
| 493 |
-
st.write(" TrustBuilder matches filters.")
|
| 494 |
-
filtered_trustbuilders[key] = value
|
| 495 |
-
|
| 496 |
-
st.write("Filtered TrustBuilders:", filtered_trustbuilders)
|
| 497 |
-
return filtered_trustbuilders
|
| 498 |
-
except Exception as e:
|
| 499 |
-
st.error(f"Error fetching TrustBuilders: {e}")
|
| 500 |
-
return {}
|
| 501 |
|
| 502 |
def delete_trustbuilder(user_id, trustbuilder_id):
|
| 503 |
try:
|
|
@@ -566,20 +491,19 @@ def load_user_content(user_id):
|
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
-
def save_content(user_id, brand, trust_builder_text, trust_bucket
|
| 570 |
try:
|
| 571 |
-
|
|
|
|
| 572 |
data = {
|
| 573 |
"brand": str(brand),
|
| 574 |
"message": str(trust_builder_text),
|
| 575 |
-
"bucket": str(trust_bucket)
|
| 576 |
}
|
| 577 |
-
st.write("Saving TrustBuilder
|
| 578 |
-
db.child(
|
| 579 |
-
st.success(f"TrustBuilder saved
|
| 580 |
except Exception as e:
|
| 581 |
st.error(f"Error saving TrustBuilder: {e}")
|
| 582 |
-
|
| 583 |
|
| 584 |
def ai_allocate_trust_bucket(trust_builder_text):
|
| 585 |
# Implement your AI allocation logic here
|
|
@@ -596,8 +520,6 @@ def download_link(content, filename):
|
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
-
|
| 600 |
-
|
| 601 |
def fetch_documents(user_id):
|
| 602 |
try:
|
| 603 |
docs = db.child("users").child(user_id).child("documents").get().val()
|
|
@@ -756,34 +678,13 @@ def side():
|
|
| 756 |
)
|
| 757 |
st.markdown("For detailed descriptions, visit [Academy](https://www.trustifier.ai/account/academy)")
|
| 758 |
|
| 759 |
-
|
| 760 |
-
trust_buckets = ["S", "D", "R", "B", "V", "C"]
|
| 761 |
-
bucket_labels = ["Stability", "Development", "Relationship", "Benefit", "Vision", "Competence"]
|
| 762 |
-
|
| 763 |
-
# Image paths and labels (pre-resized images in your folder)
|
| 764 |
-
st.sidebar.header("TrustVault®")
|
| 765 |
-
|
| 766 |
-
# CSS for scrollable container with gray border
|
| 767 |
-
st.markdown("""
|
| 768 |
-
<style>
|
| 769 |
-
.scrollable-container {
|
| 770 |
-
max-height: 300px;
|
| 771 |
-
overflow-y: auto;
|
| 772 |
-
border: 1px solid gray;
|
| 773 |
-
padding: 10px;
|
| 774 |
-
border-radius: 5px;
|
| 775 |
-
background-color: #f9f9f9;
|
| 776 |
-
}
|
| 777 |
-
</style>
|
| 778 |
-
""", unsafe_allow_html=True)
|
| 779 |
-
|
| 780 |
-
# Container for Saved Documents
|
| 781 |
with st.container():
|
| 782 |
st.subheader("Saved Documents")
|
| 783 |
st.write("Save documents like your brand tonality, key phrases, or segments here.")
|
| 784 |
st.markdown('<div class="scrollable-container">', unsafe_allow_html=True)
|
| 785 |
|
| 786 |
-
|
|
|
|
| 787 |
|
| 788 |
if docs:
|
| 789 |
for doc_id, doc_data in docs.items():
|
|
@@ -814,12 +715,12 @@ def side():
|
|
| 814 |
if uploaded_files:
|
| 815 |
md_contents = []
|
| 816 |
for file in uploaded_files:
|
| 817 |
-
md_content = convert_file_to_md(file)
|
| 818 |
if md_content:
|
| 819 |
md_contents.append(md_content)
|
| 820 |
if md_contents:
|
| 821 |
merged_md_content = merge_markdown_contents(md_contents)
|
| 822 |
-
public_url = upload_to_firebase(st.session_state["wix_user_id"], merged_md_content)
|
| 823 |
if public_url:
|
| 824 |
# Save document reference and public URL to Firebase
|
| 825 |
doc_id = str(uuid.uuid4())
|
|
@@ -828,7 +729,6 @@ def side():
|
|
| 828 |
"public_url": public_url
|
| 829 |
})
|
| 830 |
st.success("Files uploaded and saved successfully!")
|
| 831 |
-
st.markdown(f"[View your knowledge base here]({public_url})", unsafe_allow_html=True)
|
| 832 |
st.experimental_rerun()
|
| 833 |
else:
|
| 834 |
st.warning("No valid files uploaded.")
|
|
@@ -836,57 +736,59 @@ def side():
|
|
| 836 |
st.warning("Please select at least one file to upload.")
|
| 837 |
|
| 838 |
# Show My TrustBuilders Section
|
| 839 |
-
st.subheader("Show
|
| 840 |
search_query = st.text_input("Search by keyword", key="search_query")
|
| 841 |
-
|
| 842 |
-
|
| 843 |
-
|
| 844 |
-
|
| 845 |
-
|
| 846 |
-
selected_bucket = st.selectbox("Select Trust Bucket", options=bucket_options, key="selected_bucket")
|
| 847 |
|
| 848 |
if st.button("Show TrustBuilders"):
|
| 849 |
-
|
| 850 |
-
|
| 851 |
-
|
| 852 |
-
|
| 853 |
-
|
| 854 |
-
|
| 855 |
-
|
| 856 |
-
|
| 857 |
-
|
| 858 |
-
|
| 859 |
-
st.write(f"
|
| 860 |
-
st.write(f"Message: {
|
| 861 |
else:
|
| 862 |
st.write("No TrustBuilders found.")
|
| 863 |
|
| 864 |
-
# Trust Bucket Selection for Saving
|
| 865 |
-
st.write("Choose the Trust Bucket®")
|
| 866 |
-
cols = st.columns(len(trust_buckets))
|
| 867 |
-
for idx, (bucket, label) in enumerate(zip(trust_buckets, bucket_labels)):
|
| 868 |
-
with cols[idx]:
|
| 869 |
-
if st.button(f"{bucket}", key=f"bucket_{label}"):
|
| 870 |
-
st.write(f"Selected Trust Bucket: {label}")
|
| 871 |
-
st.session_state["selected_bucket_to_save"] = label
|
| 872 |
-
|
| 873 |
# Save TrustBuilders Section
|
| 874 |
st.subheader("Save TrustBuilders®")
|
| 875 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 876 |
trust_builder_text = st.text_area("Type/paste Trust Builder®", height=100)
|
| 877 |
|
| 878 |
-
|
| 879 |
-
|
| 880 |
-
|
| 881 |
-
|
| 882 |
-
|
| 883 |
-
|
| 884 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 885 |
|
| 886 |
|
| 887 |
-
# Initialize embeddings and FAISS index only when wix_user_id is set
|
| 888 |
|
| 889 |
|
|
|
|
| 890 |
side()
|
| 891 |
if st.session_state.get("wix_user_id") and "faiss_db" not in st.session_state:
|
| 892 |
refresh_faiss_index()
|
|
|
|
| 166 |
return None
|
| 167 |
|
| 168 |
|
| 169 |
+
def fetch_trustbuilders(user_id):
|
| 170 |
try:
|
| 171 |
+
path = f"users/{user_id}/TrustBuilder"
|
| 172 |
+
return db.child(path).get().val() or {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
except Exception as e:
|
| 174 |
st.error(f"Error fetching TrustBuilders: {e}")
|
| 175 |
return {}
|
|
|
|
| 176 |
|
| 177 |
def delete_trustbuilder(user_id, trustbuilder_id):
|
| 178 |
try:
|
|
|
|
| 423 |
|
| 424 |
|
| 425 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 426 |
|
| 427 |
def delete_trustbuilder(user_id, trustbuilder_id):
|
| 428 |
try:
|
|
|
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
+
def save_content(user_id, brand, trust_builder_text, trust_bucket):
|
| 495 |
try:
|
| 496 |
+
# Save directly under the bucket name
|
| 497 |
+
path = f"users/{user_id}/TrustBuilder/{trust_bucket}"
|
| 498 |
data = {
|
| 499 |
"brand": str(brand),
|
| 500 |
"message": str(trust_builder_text),
|
|
|
|
| 501 |
}
|
| 502 |
+
st.write(f"Saving TrustBuilder to path: {path}")
|
| 503 |
+
db.child(path).set(data)
|
| 504 |
+
st.success(f"TrustBuilder saved under the '{trust_bucket}' bucket.")
|
| 505 |
except Exception as e:
|
| 506 |
st.error(f"Error saving TrustBuilder: {e}")
|
|
|
|
| 507 |
|
| 508 |
def ai_allocate_trust_bucket(trust_builder_text):
|
| 509 |
# Implement your AI allocation logic here
|
|
|
|
| 520 |
|
| 521 |
|
| 522 |
|
|
|
|
|
|
|
| 523 |
def fetch_documents(user_id):
|
| 524 |
try:
|
| 525 |
docs = db.child("users").child(user_id).child("documents").get().val()
|
|
|
|
| 678 |
)
|
| 679 |
st.markdown("For detailed descriptions, visit [Academy](https://www.trustifier.ai/account/academy)")
|
| 680 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 681 |
with st.container():
|
| 682 |
st.subheader("Saved Documents")
|
| 683 |
st.write("Save documents like your brand tonality, key phrases, or segments here.")
|
| 684 |
st.markdown('<div class="scrollable-container">', unsafe_allow_html=True)
|
| 685 |
|
| 686 |
+
# Placeholder: Replace with your actual document fetching function
|
| 687 |
+
docs = {} # Example: fetch_documents(st.session_state["wix_user_id"])
|
| 688 |
|
| 689 |
if docs:
|
| 690 |
for doc_id, doc_data in docs.items():
|
|
|
|
| 715 |
if uploaded_files:
|
| 716 |
md_contents = []
|
| 717 |
for file in uploaded_files:
|
| 718 |
+
md_content = convert_file_to_md(file) # Replace with your file conversion logic
|
| 719 |
if md_content:
|
| 720 |
md_contents.append(md_content)
|
| 721 |
if md_contents:
|
| 722 |
merged_md_content = merge_markdown_contents(md_contents)
|
| 723 |
+
public_url = upload_to_firebase(st.session_state["wix_user_id"], merged_md_content) # Replace with your upload logic
|
| 724 |
if public_url:
|
| 725 |
# Save document reference and public URL to Firebase
|
| 726 |
doc_id = str(uuid.uuid4())
|
|
|
|
| 729 |
"public_url": public_url
|
| 730 |
})
|
| 731 |
st.success("Files uploaded and saved successfully!")
|
|
|
|
| 732 |
st.experimental_rerun()
|
| 733 |
else:
|
| 734 |
st.warning("No valid files uploaded.")
|
|
|
|
| 736 |
st.warning("Please select at least one file to upload.")
|
| 737 |
|
| 738 |
# Show My TrustBuilders Section
|
| 739 |
+
st.subheader("Show My TrustBuilders®")
|
| 740 |
search_query = st.text_input("Search by keyword", key="search_query")
|
| 741 |
+
selected_bucket = st.selectbox(
|
| 742 |
+
"Select Trust Bucket",
|
| 743 |
+
options=["All"] + bucket_labels,
|
| 744 |
+
key="selected_bucket"
|
| 745 |
+
)
|
|
|
|
| 746 |
|
| 747 |
if st.button("Show TrustBuilders"):
|
| 748 |
+
trustbuilders = fetch_trustbuilders(st.session_state["wix_user_id"])
|
| 749 |
+
filtered_trustbuilders = {
|
| 750 |
+
bucket: data for bucket, data in trustbuilders.items()
|
| 751 |
+
if (selected_bucket == "All" or selected_bucket == bucket)
|
| 752 |
+
and (not search_query or search_query.lower() in data["message"].lower())
|
| 753 |
+
}
|
| 754 |
+
|
| 755 |
+
if filtered_trustbuilders:
|
| 756 |
+
for bucket, data in filtered_trustbuilders.items():
|
| 757 |
+
with st.expander(f"Bucket: {bucket}"):
|
| 758 |
+
st.write(f"Brand: {data['brand']}")
|
| 759 |
+
st.write(f"Message: {data['message']}")
|
| 760 |
else:
|
| 761 |
st.write("No TrustBuilders found.")
|
| 762 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 763 |
# Save TrustBuilders Section
|
| 764 |
st.subheader("Save TrustBuilders®")
|
| 765 |
+
bucket_to_save = st.selectbox(
|
| 766 |
+
"Choose Trust Bucket to Save",
|
| 767 |
+
options=bucket_labels,
|
| 768 |
+
key="bucket_to_save"
|
| 769 |
+
)
|
| 770 |
+
brand_input = st.text_input("Brand/Product/Person", key="brand_input")
|
| 771 |
trust_builder_text = st.text_area("Type/paste Trust Builder®", height=100)
|
| 772 |
|
| 773 |
+
if st.button("Save TrustBuilder"):
|
| 774 |
+
if bucket_to_save and trust_builder_text.strip():
|
| 775 |
+
save_content(
|
| 776 |
+
st.session_state["wix_user_id"],
|
| 777 |
+
brand_input,
|
| 778 |
+
trust_builder_text.strip(),
|
| 779 |
+
bucket_to_save
|
| 780 |
+
)
|
| 781 |
+
else:
|
| 782 |
+
st.warning("Please select a bucket and provide TrustBuilder text.")
|
| 783 |
+
|
| 784 |
+
|
| 785 |
+
|
| 786 |
+
|
| 787 |
|
| 788 |
|
|
|
|
| 789 |
|
| 790 |
|
| 791 |
+
|
| 792 |
side()
|
| 793 |
if st.session_state.get("wix_user_id") and "faiss_db" not in st.session_state:
|
| 794 |
refresh_faiss_index()
|