Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1620,40 +1620,29 @@ def retrieve_user_data(user_id):
|
|
| 1620 |
except Exception as e:
|
| 1621 |
st.error(f"Error loading saved content: {e}")
|
| 1622 |
|
| 1623 |
-
|
| 1624 |
def handle_memory_queries(prompt):
|
| 1625 |
prompt = prompt.lower().strip()
|
| 1626 |
|
| 1627 |
-
# Save
|
| 1628 |
-
if
|
| 1629 |
-
content_to_save =
|
| 1630 |
-
specified_bucket = None
|
| 1631 |
-
|
| 1632 |
-
# Check for explicit bucket mention in the same prompt
|
| 1633 |
-
match = re.search(r"under\s+(\w+\s*trust)", prompt, re.IGNORECASE)
|
| 1634 |
-
if match:
|
| 1635 |
-
bucket_name = match.group(1).replace("trust", "").strip()
|
| 1636 |
-
if bucket_name in ["Stability", "Development", "Relationship", "Benefit", "Vision", "Competence"]:
|
| 1637 |
-
specified_bucket = bucket_name
|
| 1638 |
-
|
| 1639 |
if content_to_save:
|
| 1640 |
-
handle_save_trustbuilder(content_to_save
|
| 1641 |
else:
|
| 1642 |
with st.chat_message("assistant"):
|
| 1643 |
-
st.markdown("Please provide content to save
|
| 1644 |
return None
|
| 1645 |
|
| 1646 |
-
#
|
| 1647 |
-
elif "show my saved trustbuilders" in prompt or "
|
| 1648 |
-
trustbuilders = st.session_state.get("
|
| 1649 |
if trustbuilders:
|
| 1650 |
-
|
| 1651 |
-
return f"Here are your saved TrustBuilders:\n{
|
| 1652 |
else:
|
| 1653 |
return "You haven't saved any TrustBuilders yet."
|
| 1654 |
|
| 1655 |
-
return None
|
| 1656 |
-
|
| 1657 |
|
| 1658 |
def delete_entry(category, entry_id):
|
| 1659 |
try:
|
|
@@ -1673,24 +1662,32 @@ def download_trustbuilder_as_md(content, trustbuilder_id):
|
|
| 1673 |
|
| 1674 |
def handle_save_trustbuilder(content, specified_bucket=None):
|
| 1675 |
"""
|
| 1676 |
-
Handles saving TrustBuilders by detecting or
|
| 1677 |
"""
|
| 1678 |
-
trust_buckets =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1679 |
bucket = specified_bucket
|
| 1680 |
|
| 1681 |
-
#
|
| 1682 |
if not bucket:
|
| 1683 |
-
for tb in trust_buckets:
|
| 1684 |
-
if
|
| 1685 |
bucket = tb
|
| 1686 |
break
|
| 1687 |
|
|
|
|
| 1688 |
if not bucket:
|
| 1689 |
-
# Store content and prompt user for bucket
|
| 1690 |
st.session_state["missing_trustbucket_content"] = content
|
| 1691 |
with st.chat_message("assistant"):
|
| 1692 |
st.markdown(
|
| 1693 |
-
"No Trust Bucket
|
| 1694 |
)
|
| 1695 |
return
|
| 1696 |
|
|
@@ -1698,7 +1695,12 @@ def handle_save_trustbuilder(content, specified_bucket=None):
|
|
| 1698 |
brand = st.session_state.get("brand_input_save", "Unknown")
|
| 1699 |
content_to_save = f"{bucket}: Brand: {brand.strip()} | {content.strip()}"
|
| 1700 |
save_content(st.session_state["wix_user_id"], content_to_save)
|
| 1701 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1702 |
|
| 1703 |
|
| 1704 |
# Function to update the message counter in a static location
|
|
|
|
| 1620 |
except Exception as e:
|
| 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 |
with st.chat_message("assistant"):
|
| 1633 |
+
st.markdown("Please provide content to save and allocate.")
|
| 1634 |
return None
|
| 1635 |
|
| 1636 |
+
# Show saved TrustBuilders
|
| 1637 |
+
elif "show my saved trustbuilders" in prompt or "find my saved trustbuilders" in prompt:
|
| 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 |
+
return f"Here are your saved TrustBuilders:\n{saved_content}"
|
| 1642 |
else:
|
| 1643 |
return "You haven't saved any TrustBuilders yet."
|
| 1644 |
|
| 1645 |
+
return None
|
|
|
|
| 1646 |
|
| 1647 |
def delete_entry(category, entry_id):
|
| 1648 |
try:
|
|
|
|
| 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": ["secure", "reliable", "consistent", "stable"],
|
| 1669 |
+
"Development": ["growth", "future", "plan", "innovate", "strategy"],
|
| 1670 |
+
"Relationship": ["trust", "partnership", "collaborate", "customer"],
|
| 1671 |
+
"Benefit": ["value", "profit", "advantage", "benefit"],
|
| 1672 |
+
"Vision": ["future", "goal", "mission", "aspire", "dream"],
|
| 1673 |
+
"Competence": ["skill", "expertise", "knowledge", "competent", "ability"]
|
| 1674 |
+
}
|
| 1675 |
+
|
| 1676 |
bucket = specified_bucket
|
| 1677 |
|
| 1678 |
+
# Automatically allocate bucket if not provided
|
| 1679 |
if not bucket:
|
| 1680 |
+
for tb, keywords in trust_buckets.items():
|
| 1681 |
+
if any(keyword in content.lower() for keyword in keywords):
|
| 1682 |
bucket = tb
|
| 1683 |
break
|
| 1684 |
|
| 1685 |
+
# If still no bucket found, prompt the user
|
| 1686 |
if not bucket:
|
|
|
|
| 1687 |
st.session_state["missing_trustbucket_content"] = content
|
| 1688 |
with st.chat_message("assistant"):
|
| 1689 |
st.markdown(
|
| 1690 |
+
"No Trust Bucket could be allocated automatically. Please indicate the Trust Bucket (e.g., Stability, Development, Relationship, Benefit, Vision, Competence)."
|
| 1691 |
)
|
| 1692 |
return
|
| 1693 |
|
|
|
|
| 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 |
+
# Confirm saving to the user
|
| 1700 |
+
with st.chat_message("assistant"):
|
| 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
|