Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -452,49 +452,34 @@ def load_user_content(user_id):
|
|
| 452 |
except Exception as e:
|
| 453 |
st.info("not loaded ")
|
| 454 |
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
|
|
|
|
|
|
|
|
|
| 459 |
try:
|
| 460 |
entry_id = str(uuid.uuid4())
|
| 461 |
firebase_key = "TrustBuilder" if content_type.lower() == "trustbuilder" else "BrandTonality"
|
| 462 |
|
| 463 |
-
# Save
|
| 464 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 465 |
|
| 466 |
-
# Update `st.session_state` for immediate display in sidebar and chatbot
|
| 467 |
if firebase_key not in st.session_state:
|
| 468 |
st.session_state[firebase_key] = {}
|
| 469 |
-
st.session_state[firebase_key][entry_id] =
|
| 470 |
-
|
| 471 |
-
# Display save confirmation without showing any ID or debug information
|
| 472 |
-
display_save_confirmation(content_type.capitalize())
|
| 473 |
|
|
|
|
| 474 |
except Exception as e:
|
| 475 |
-
st.error(f"
|
| 476 |
|
| 477 |
-
|
| 478 |
-
def display_saved_trustbuilders():
|
| 479 |
-
|
| 480 |
-
# Display TrustBuilders with delete buttons
|
| 481 |
-
st.sidebar.subheader("Saved TrustBuilders")
|
| 482 |
-
trustbuilders = st.session_state.get("TrustBuilder", {})
|
| 483 |
-
for trustbuilder_id, trustbuilder_data in trustbuilders.items():
|
| 484 |
-
message = trustbuilder_data.get("message", "No message available")
|
| 485 |
-
st.sidebar.markdown(f"- {message[:50]}...")
|
| 486 |
-
if st.sidebar.button("Delete", key=f"del_tb_{trustbuilder_id}"):
|
| 487 |
-
delete_entry("TrustBuilder", trustbuilder_id, "TrustBuilder")
|
| 488 |
-
|
| 489 |
-
# Display Brand Tonality entries with delete buttons
|
| 490 |
-
st.sidebar.subheader("Saved Brand Tonality")
|
| 491 |
-
brand_tonality = st.session_state.get("BrandTonality", {})
|
| 492 |
-
for tonality_id, tonality_data in brand_tonality.items():
|
| 493 |
-
message = tonality_data.get("message", "No message available")
|
| 494 |
-
st.sidebar.markdown(f"- {message[:50]}...")
|
| 495 |
-
if st.sidebar.button("Delete", key=f"del_bt_{tonality_id}"):
|
| 496 |
-
delete_entry("BrandTonality", tonality_id, "BrandTonality")
|
| 497 |
|
|
|
|
| 498 |
|
| 499 |
def download_link(content, filename):
|
| 500 |
"""
|
|
@@ -519,7 +504,7 @@ def delete_document(user_id, doc_id):
|
|
| 519 |
try:
|
| 520 |
db.child("users").child(user_id).child("KnowledgeBase").child(doc_id).remove()
|
| 521 |
st.success("Document deleted successfully!")
|
| 522 |
-
st.
|
| 523 |
except Exception as e:
|
| 524 |
st.error(f"Error deleting document: {e}")
|
| 525 |
|
|
@@ -690,21 +675,7 @@ def side():
|
|
| 690 |
if st.button("Delete"):
|
| 691 |
st.warning("Select a document to delete from the list below.")
|
| 692 |
|
| 693 |
-
|
| 694 |
-
st.sidebar.markdown(
|
| 695 |
-
"""
|
| 696 |
-
<style>
|
| 697 |
-
.scrollable-container {
|
| 698 |
-
height: 200px;
|
| 699 |
-
overflow-y: auto;
|
| 700 |
-
border: 1px solid #ddd;
|
| 701 |
-
padding: 10px;
|
| 702 |
-
background-color: #f5f5f5;
|
| 703 |
-
}
|
| 704 |
-
</style>
|
| 705 |
-
""",
|
| 706 |
-
unsafe_allow_html=True
|
| 707 |
-
)
|
| 708 |
|
| 709 |
docs = fetch_documents(st.session_state["wix_user_id"])
|
| 710 |
st.sidebar.markdown('<div class="scrollable-container">', unsafe_allow_html=True)
|
|
@@ -724,16 +695,13 @@ def side():
|
|
| 724 |
|
| 725 |
# Show My TrustBuilders Section
|
| 726 |
st.sidebar.subheader("Show my TrustBuilders®")
|
| 727 |
-
search_query = st.sidebar.text_input("Search by keyword",key="keyword")
|
| 728 |
if search_query:
|
| 729 |
search_results = {k: v for k, v in st.session_state.get("TrustBuilder", {}).items() if search_query.lower() in v["message"].lower()}
|
| 730 |
for result_id, result_data in search_results.items():
|
| 731 |
st.sidebar.write(f"- {result_data['message'][:50]}")
|
| 732 |
|
| 733 |
-
|
| 734 |
-
if st.sidebar.button("Show"):
|
| 735 |
-
st.write("Show clicked")
|
| 736 |
-
|
| 737 |
st.sidebar.write("and choose the Trust Bucket®")
|
| 738 |
trust_buckets = ["S", "D", "R", "B", "V", "C"]
|
| 739 |
bucket_labels = ["Stability", "Development", "Relationship", "Benefit", "Vision", "Competence"]
|
|
@@ -753,12 +721,13 @@ def side():
|
|
| 753 |
for idx, (bucket, label) in enumerate(zip(trust_buckets, bucket_labels)):
|
| 754 |
with st.sidebar:
|
| 755 |
if st.button(f"{bucket}", key=f"allocate_{label}"):
|
| 756 |
-
save_content(st.session_state["wix_user_id"], trust_builder_text, label)
|
| 757 |
|
| 758 |
if st.sidebar.button("Let AI allocate"):
|
| 759 |
st.write("AI allocated the Trust Bucket")
|
| 760 |
|
| 761 |
|
|
|
|
| 762 |
side()
|
| 763 |
# Load knowledge base
|
| 764 |
|
|
@@ -1426,23 +1395,12 @@ def handle_memory_queries(prompt):
|
|
| 1426 |
return None # If no recognized command, proceed with general handling
|
| 1427 |
|
| 1428 |
|
| 1429 |
-
def delete_entry(category, entry_id
|
| 1430 |
-
"""
|
| 1431 |
-
Deletes an entry from Firebase and updates the session state to reflect the deletion.
|
| 1432 |
-
"""
|
| 1433 |
try:
|
| 1434 |
-
# Get user ID from session state
|
| 1435 |
user_id = st.session_state["wix_user_id"]
|
| 1436 |
-
|
| 1437 |
-
# Remove the entry from Firebase
|
| 1438 |
db.child("users").child(user_id).child(category).child(entry_id).remove()
|
| 1439 |
-
|
| 1440 |
-
|
| 1441 |
-
if session_key in st.session_state and entry_id in st.session_state[session_key]:
|
| 1442 |
-
del st.session_state[session_key][entry_id]
|
| 1443 |
-
|
| 1444 |
-
# Refresh the app to immediately reflect the change in the sidebar
|
| 1445 |
-
st.rerun()
|
| 1446 |
except Exception as e:
|
| 1447 |
st.error(f"Error deleting entry: {e}")
|
| 1448 |
|
|
@@ -1455,7 +1413,7 @@ def download_trustbuilder_as_md(content, trustbuilder_id):
|
|
| 1455 |
|
| 1456 |
def handle_save_trustbuilder_or_tonality(user_id, content, type_name):
|
| 1457 |
save_content(user_id, content, type_name)
|
| 1458 |
-
|
| 1459 |
|
| 1460 |
|
| 1461 |
|
|
|
|
| 452 |
except Exception as e:
|
| 453 |
st.info("not loaded ")
|
| 454 |
|
| 455 |
+
|
| 456 |
+
|
| 457 |
+
|
| 458 |
+
|
| 459 |
+
|
| 460 |
+
|
| 461 |
+
def save_content(user_id, content, trust_bucket, content_type="TrustBuilder"):
|
| 462 |
try:
|
| 463 |
entry_id = str(uuid.uuid4())
|
| 464 |
firebase_key = "TrustBuilder" if content_type.lower() == "trustbuilder" else "BrandTonality"
|
| 465 |
|
| 466 |
+
# Save with metadata (trust_bucket for TrustBuilders)
|
| 467 |
+
data = {"message": content}
|
| 468 |
+
if content_type == "TrustBuilder":
|
| 469 |
+
data["trust_bucket"] = trust_bucket
|
| 470 |
+
|
| 471 |
+
db.child("users").child(user_id).child(firebase_key).child(entry_id).set(data)
|
| 472 |
|
|
|
|
| 473 |
if firebase_key not in st.session_state:
|
| 474 |
st.session_state[firebase_key] = {}
|
| 475 |
+
st.session_state[firebase_key][entry_id] = data
|
|
|
|
|
|
|
|
|
|
| 476 |
|
| 477 |
+
st.success(f"{content_type.capitalize()} saved successfully!")
|
| 478 |
except Exception as e:
|
| 479 |
+
st.error(f"Error saving {content_type}: {e}")
|
| 480 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 481 |
|
| 482 |
+
|
| 483 |
|
| 484 |
def download_link(content, filename):
|
| 485 |
"""
|
|
|
|
| 504 |
try:
|
| 505 |
db.child("users").child(user_id).child("KnowledgeBase").child(doc_id).remove()
|
| 506 |
st.success("Document deleted successfully!")
|
| 507 |
+
st.rerun() # Refresh the list after deletion
|
| 508 |
except Exception as e:
|
| 509 |
st.error(f"Error deleting document: {e}")
|
| 510 |
|
|
|
|
| 675 |
if st.button("Delete"):
|
| 676 |
st.warning("Select a document to delete from the list below.")
|
| 677 |
|
| 678 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 679 |
|
| 680 |
docs = fetch_documents(st.session_state["wix_user_id"])
|
| 681 |
st.sidebar.markdown('<div class="scrollable-container">', unsafe_allow_html=True)
|
|
|
|
| 695 |
|
| 696 |
# Show My TrustBuilders Section
|
| 697 |
st.sidebar.subheader("Show my TrustBuilders®")
|
| 698 |
+
search_query = st.sidebar.text_input("Search by keyword", key="keyword")
|
| 699 |
if search_query:
|
| 700 |
search_results = {k: v for k, v in st.session_state.get("TrustBuilder", {}).items() if search_query.lower() in v["message"].lower()}
|
| 701 |
for result_id, result_data in search_results.items():
|
| 702 |
st.sidebar.write(f"- {result_data['message'][:50]}")
|
| 703 |
|
| 704 |
+
# Trust Bucket Selection
|
|
|
|
|
|
|
|
|
|
| 705 |
st.sidebar.write("and choose the Trust Bucket®")
|
| 706 |
trust_buckets = ["S", "D", "R", "B", "V", "C"]
|
| 707 |
bucket_labels = ["Stability", "Development", "Relationship", "Benefit", "Vision", "Competence"]
|
|
|
|
| 721 |
for idx, (bucket, label) in enumerate(zip(trust_buckets, bucket_labels)):
|
| 722 |
with st.sidebar:
|
| 723 |
if st.button(f"{bucket}", key=f"allocate_{label}"):
|
| 724 |
+
save_content(st.session_state["wix_user_id"], trust_builder_text, trust_bucket=label)
|
| 725 |
|
| 726 |
if st.sidebar.button("Let AI allocate"):
|
| 727 |
st.write("AI allocated the Trust Bucket")
|
| 728 |
|
| 729 |
|
| 730 |
+
|
| 731 |
side()
|
| 732 |
# Load knowledge base
|
| 733 |
|
|
|
|
| 1395 |
return None # If no recognized command, proceed with general handling
|
| 1396 |
|
| 1397 |
|
| 1398 |
+
def delete_entry(category, entry_id):
|
|
|
|
|
|
|
|
|
|
| 1399 |
try:
|
|
|
|
| 1400 |
user_id = st.session_state["wix_user_id"]
|
|
|
|
|
|
|
| 1401 |
db.child("users").child(user_id).child(category).child(entry_id).remove()
|
| 1402 |
+
st.session_state[category].pop(entry_id, None)
|
| 1403 |
+
st.success(f"{category} entry deleted successfully!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1404 |
except Exception as e:
|
| 1405 |
st.error(f"Error deleting entry: {e}")
|
| 1406 |
|
|
|
|
| 1413 |
|
| 1414 |
def handle_save_trustbuilder_or_tonality(user_id, content, type_name):
|
| 1415 |
save_content(user_id, content, type_name)
|
| 1416 |
+
|
| 1417 |
|
| 1418 |
|
| 1419 |
|