Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1621,29 +1621,46 @@ def retrieve_user_data(user_id):
|
|
| 1621 |
st.error(f"Error loading saved content: {e}")
|
| 1622 |
|
| 1623 |
def handle_memory_queries(prompt):
|
|
|
|
|
|
|
|
|
|
| 1624 |
prompt = prompt.lower().strip()
|
| 1625 |
|
| 1626 |
# Save and allocate TrustBuilder
|
| 1627 |
if "save and allocate" in prompt:
|
| 1628 |
content_to_save = prompt.replace("save and allocate:", "").strip()
|
| 1629 |
if content_to_save:
|
| 1630 |
-
handle_save_trustbuilder(content_to_save)
|
| 1631 |
else:
|
| 1632 |
-
|
| 1633 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1634 |
return None
|
| 1635 |
|
| 1636 |
# Show saved TrustBuilders
|
| 1637 |
-
elif "
|
| 1638 |
trustbuilders = fetch_trustbuilders(st.session_state.get("wix_user_id", "default_user"))
|
| 1639 |
if trustbuilders:
|
| 1640 |
saved_content = "\n".join([f"- {entry['message']}" for entry in trustbuilders.values()])
|
| 1641 |
-
|
| 1642 |
else:
|
| 1643 |
-
|
| 1644 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1645 |
return None
|
| 1646 |
-
|
| 1647 |
def delete_entry(category, entry_id):
|
| 1648 |
try:
|
| 1649 |
user_id = st.session_state["wix_user_id"]
|
|
@@ -1660,17 +1677,36 @@ def download_trustbuilder_as_md(content, trustbuilder_id):
|
|
| 1660 |
download_link = f'<a href="data:text/markdown;base64,{b64_content}" download="TrustBuilder_{trustbuilder_id}.md">Download</a>'
|
| 1661 |
st.sidebar.markdown(download_link, unsafe_allow_html=True)
|
| 1662 |
|
|
|
|
| 1663 |
def handle_save_trustbuilder(content, specified_bucket=None):
|
| 1664 |
"""
|
| 1665 |
Handles saving TrustBuilders by detecting or automatically allocating the Trust Bucket.
|
| 1666 |
"""
|
| 1667 |
trust_buckets = {
|
| 1668 |
-
"Stability": [
|
| 1669 |
-
|
| 1670 |
-
|
| 1671 |
-
|
| 1672 |
-
"
|
| 1673 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1674 |
}
|
| 1675 |
|
| 1676 |
bucket = specified_bucket
|
|
@@ -1682,27 +1718,24 @@ def handle_save_trustbuilder(content, specified_bucket=None):
|
|
| 1682 |
bucket = tb
|
| 1683 |
break
|
| 1684 |
|
| 1685 |
-
# If
|
| 1686 |
if not bucket:
|
| 1687 |
st.session_state["missing_trustbucket_content"] = content
|
| 1688 |
-
|
| 1689 |
-
|
| 1690 |
-
|
| 1691 |
-
|
| 1692 |
-
return
|
| 1693 |
|
| 1694 |
# Save TrustBuilder with detected/provided bucket
|
| 1695 |
brand = st.session_state.get("brand_input_save", "Unknown")
|
| 1696 |
content_to_save = f"{bucket}: Brand: {brand.strip()} | {content.strip()}"
|
| 1697 |
save_content(st.session_state["wix_user_id"], content_to_save)
|
| 1698 |
|
| 1699 |
-
#
|
| 1700 |
-
|
| 1701 |
-
st.markdown(f"TrustBuilder allocated to **{bucket}** and saved successfully!")
|
| 1702 |
-
|
| 1703 |
|
| 1704 |
|
| 1705 |
-
|
| 1706 |
# Function to update the message counter in a static location
|
| 1707 |
|
| 1708 |
if "email" not in st.session_state:
|
|
|
|
| 1621 |
st.error(f"Error loading saved content: {e}")
|
| 1622 |
|
| 1623 |
def handle_memory_queries(prompt):
|
| 1624 |
+
"""
|
| 1625 |
+
Main function to handle user commands and allocate Trust Buckets.
|
| 1626 |
+
"""
|
| 1627 |
prompt = prompt.lower().strip()
|
| 1628 |
|
| 1629 |
# Save and allocate TrustBuilder
|
| 1630 |
if "save and allocate" in prompt:
|
| 1631 |
content_to_save = prompt.replace("save and allocate:", "").strip()
|
| 1632 |
if content_to_save:
|
| 1633 |
+
assistant_response = handle_save_trustbuilder(content_to_save)
|
| 1634 |
else:
|
| 1635 |
+
assistant_response = "Please provide content to save and allocate."
|
| 1636 |
+
|
| 1637 |
+
# Save response to chat history and display it
|
| 1638 |
+
st.session_state.chat_history.append({"role": "assistant", "content": assistant_response})
|
| 1639 |
+
with st.chat_message("assistant"):
|
| 1640 |
+
st.markdown(assistant_response)
|
| 1641 |
return None
|
| 1642 |
|
| 1643 |
# Show saved TrustBuilders
|
| 1644 |
+
elif "find my saved trustbuilders" in prompt or "show my saved trustbuilders" in prompt:
|
| 1645 |
trustbuilders = fetch_trustbuilders(st.session_state.get("wix_user_id", "default_user"))
|
| 1646 |
if trustbuilders:
|
| 1647 |
saved_content = "\n".join([f"- {entry['message']}" for entry in trustbuilders.values()])
|
| 1648 |
+
assistant_response = f"Here are your saved TrustBuilders:\n{saved_content}"
|
| 1649 |
else:
|
| 1650 |
+
assistant_response = "You haven't saved any TrustBuilders yet."
|
| 1651 |
|
| 1652 |
+
# Save response to chat history and display it
|
| 1653 |
+
st.session_state.chat_history.append({"role": "assistant", "content": assistant_response})
|
| 1654 |
+
with st.chat_message("assistant"):
|
| 1655 |
+
st.markdown(assistant_response)
|
| 1656 |
+
return None
|
| 1657 |
+
|
| 1658 |
+
# Default case for generic AI response
|
| 1659 |
+
assistant_response = "I'm sorry, I couldn't understand your request."
|
| 1660 |
+
st.session_state.chat_history.append({"role": "assistant", "content": assistant_response})
|
| 1661 |
+
with st.chat_message("assistant"):
|
| 1662 |
+
st.markdown(assistant_response)
|
| 1663 |
return None
|
|
|
|
| 1664 |
def delete_entry(category, entry_id):
|
| 1665 |
try:
|
| 1666 |
user_id = st.session_state["wix_user_id"]
|
|
|
|
| 1677 |
download_link = f'<a href="data:text/markdown;base64,{b64_content}" download="TrustBuilder_{trustbuilder_id}.md">Download</a>'
|
| 1678 |
st.sidebar.markdown(download_link, unsafe_allow_html=True)
|
| 1679 |
|
| 1680 |
+
|
| 1681 |
def handle_save_trustbuilder(content, specified_bucket=None):
|
| 1682 |
"""
|
| 1683 |
Handles saving TrustBuilders by detecting or automatically allocating the Trust Bucket.
|
| 1684 |
"""
|
| 1685 |
trust_buckets = {
|
| 1686 |
+
"Stability": [
|
| 1687 |
+
"secure", "reliable", "consistent", "stable", "safety", "protection", "trustworthy",
|
| 1688 |
+
"dependable", "solid", "durable", "continuity", "assurance"
|
| 1689 |
+
],
|
| 1690 |
+
"Development": [
|
| 1691 |
+
"growth", "future", "plan", "innovate", "strategy", "building", "improvement", "progress",
|
| 1692 |
+
"expansion", "visionary", "change", "adaptation", "forward-thinking"
|
| 1693 |
+
],
|
| 1694 |
+
"Relationship": [
|
| 1695 |
+
"trust", "partnership", "collaborate", "customer", "engage", "connect", "loyalty",
|
| 1696 |
+
"bond", "interaction", "relationship", "teamwork", "communication"
|
| 1697 |
+
],
|
| 1698 |
+
"Benefit": [
|
| 1699 |
+
"value", "profit", "advantage", "benefit", "gain", "cost-effective", "economical",
|
| 1700 |
+
"saving", "reward", "output", "utility", "return", "efficiency"
|
| 1701 |
+
],
|
| 1702 |
+
"Vision": [
|
| 1703 |
+
"goal", "mission", "aspire", "dream", "visionary", "great", "future", "ideal",
|
| 1704 |
+
"ambition", "long-term", "objective", "focus", "drive"
|
| 1705 |
+
],
|
| 1706 |
+
"Competence": [
|
| 1707 |
+
"skill", "expertise", "knowledge", "competent", "ability", "talent", "proficiency",
|
| 1708 |
+
"capability", "qualification", "training", "effectiveness", "specialization"
|
| 1709 |
+
]
|
| 1710 |
}
|
| 1711 |
|
| 1712 |
bucket = specified_bucket
|
|
|
|
| 1718 |
bucket = tb
|
| 1719 |
break
|
| 1720 |
|
| 1721 |
+
# If no bucket can be allocated, prompt the user
|
| 1722 |
if not bucket:
|
| 1723 |
st.session_state["missing_trustbucket_content"] = content
|
| 1724 |
+
return (
|
| 1725 |
+
"No Trust Bucket could be allocated automatically. "
|
| 1726 |
+
"Please indicate the Trust Bucket (e.g., Stability, Development, Relationship, Benefit, Vision, Competence)."
|
| 1727 |
+
)
|
|
|
|
| 1728 |
|
| 1729 |
# Save TrustBuilder with detected/provided bucket
|
| 1730 |
brand = st.session_state.get("brand_input_save", "Unknown")
|
| 1731 |
content_to_save = f"{bucket}: Brand: {brand.strip()} | {content.strip()}"
|
| 1732 |
save_content(st.session_state["wix_user_id"], content_to_save)
|
| 1733 |
|
| 1734 |
+
# Return success response
|
| 1735 |
+
return f"TrustBuilder allocated to **{bucket}** and saved successfully!"
|
|
|
|
|
|
|
| 1736 |
|
| 1737 |
|
| 1738 |
+
|
| 1739 |
# Function to update the message counter in a static location
|
| 1740 |
|
| 1741 |
if "email" not in st.session_state:
|