Wajahat698 commited on
Commit
f6fbb60
·
verified ·
1 Parent(s): 5fd0b22

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -56
app.py CHANGED
@@ -1569,30 +1569,27 @@ def retrieve_user_data(user_id):
1569
  st.error(f"Error loading saved content: {e}")
1570
 
1571
 
1572
-
1573
-
1574
-
1575
- # Function to handle queries about saved TrustBuilders or Brand Tonality
1576
  def handle_memory_queries(prompt):
1577
  prompt = prompt.lower().strip()
1578
 
1579
- # Save as TrustBuilder, removing the phrase from the content
1580
- if "save this as trustbuilder" in prompt:
1581
- content_to_save = prompt.replace("save this as trustbuilder", "").strip()
1582
- if content_to_save: # Only save if there's actual content
1583
- save_content(st.session_state["wix_user_id"], content_to_save)
1584
- return "TrustBuilder saved successfully!"
 
 
 
 
 
 
 
 
1585
  else:
1586
- return "Please provide content to save as TrustBuilder."
1587
-
1588
- # Save as Brand Tonality, removing the phrase from the content
1589
- elif "save this as brand tonality" in prompt:
1590
- content_to_save = prompt.replace("save this as brand tonality", "").strip()
1591
- if content_to_save: # Only save if there's actual content
1592
- save_content(st.session_state["wix_user_id"], content_to_save)
1593
- return "Brand Tonality saved successfully!"
1594
- else:
1595
- return "Please provide content to save as Brand Tonality."
1596
 
1597
  # Retrieve saved TrustBuilders
1598
  elif "show my saved trustbuilders" in prompt or "find my saved trustbuilders" in prompt:
@@ -1614,9 +1611,8 @@ def handle_memory_queries(prompt):
1614
  else:
1615
  return "You haven't saved any Brand Tonality entries yet."
1616
 
1617
- return None # If no recognized command, proceed with general handling
1618
-
1619
-
1620
  def delete_entry(category, entry_id):
1621
  try:
1622
  user_id = st.session_state["wix_user_id"]
@@ -1648,17 +1644,20 @@ def handle_save_trustbuilder(content, specified_bucket=None):
1648
  break
1649
 
1650
  if not bucket:
1651
- st.warning("No Trust Bucket specified. Please indicate the Trust Bucket.")
1652
  st.session_state["missing_trustbucket_content"] = content
 
 
 
 
1653
  return
1654
 
1655
  # Save TrustBuilder with detected/provided bucket
1656
  brand = st.session_state.get("brand_input_save", "Unknown")
1657
  content_to_save = f"{bucket}: Brand: {brand.strip()} | {content.strip()}"
1658
  save_content(st.session_state["wix_user_id"], content_to_save)
1659
- st.success(f"TrustBuilder saved under '{bucket}' Trust.")
1660
-
1661
-
1662
 
1663
 
1664
  # Function to update the message counter in a static location
@@ -1672,6 +1671,9 @@ if "message_limit" not in st.session_state:
1672
  if "used_messages" not in st.session_state:
1673
  st.session_state["used_messages"] = 0
1674
 
 
 
 
1675
  def initialize_user_session():
1676
  """
1677
  Initialize user session and ensure user data exists in Firebase.
@@ -1730,42 +1732,23 @@ if st.session_state["used_messages"] < st.session_state["message_limit"]:
1730
  if prompt:
1731
  st.session_state.chat_started = True
1732
  st.session_state.chat_history.append({"role": "user", "content": prompt})
1733
- if "save this as trustbuilder" in prompt.lower():
1734
- content_to_save = prompt.replace("save this as trustbuilder", "").strip()
1735
- specified_bucket = None
1736
-
1737
- # Check for explicit bucket mention in the same prompt
1738
- match = re.search(r"under\s+(\w+\s*trust)", prompt, re.IGNORECASE)
1739
- if match:
1740
- bucket_name = match.group(1).replace("trust", "").strip()
1741
- if bucket_name in ["Stability", "Development", "Relationship", "Benefit", "Vision", "Competence"]:
1742
- specified_bucket = bucket_name
1743
-
1744
- if content_to_save:
1745
- handle_save_trustbuilder(content_to_save, specified_bucket)
1746
- else:
1747
- st.warning("Please provide content to save as TrustBuilder.")
1748
-
1749
-
1750
 
1751
  # Handle save commands based on the user prompt
1752
  memory_response = handle_memory_queries(prompt)
1753
  if memory_response:
1754
  with st.chat_message("assistant"):
1755
  st.markdown(memory_response)
1756
- else:
1757
- save_as_trustbuilder = re.search(r"\b(save|add|store)\s*(this)?\s*(as)?\s*(trust\s*builder|trustbuilder)\b", prompt, re.IGNORECASE)
1758
- save_as_tonality = re.search(r"\b(save|add|store)\s*(this)?\s*(as)?\s*(brand\s*tonality|tonality)\b", prompt, re.IGNORECASE)
1759
-
1760
- if save_as_trustbuilder or save_as_tonality:
1761
- user_id = st.session_state["wix_user_id"]
1762
- if save_as_trustbuilder:
1763
- handle_save_trustbuilder_or_tonality(user_id, prompt, "trustbuilder")
1764
- elif save_as_tonality:
1765
- handle_save_trustbuilder_or_tonality(user_id, prompt, "brandtonality")
1766
-
1767
-
1768
  else:
 
 
 
1769
  # Generate a response with AI for general queries
1770
  with st.chat_message("user"):
1771
  st.markdown(prompt)
 
1569
  st.error(f"Error loading saved content: {e}")
1570
 
1571
 
 
 
 
 
1572
  def handle_memory_queries(prompt):
1573
  prompt = prompt.lower().strip()
1574
 
1575
+ # Save as TrustBuilder
1576
+ if re.search(r"\b(keep|add|save|store)\s*(this)?\s*(as)?\s*(trust\s*builder|trustbuilder)\b", prompt, re.IGNORECASE):
1577
+ content_to_save = re.sub(r"\b(keep|add|save|store)\s*(this)?\s*(as)?\s*(trust\s*builder|trustbuilder)\b", "", prompt, flags=re.IGNORECASE).strip()
1578
+ specified_bucket = None
1579
+
1580
+ # Check for explicit bucket mention in the same prompt
1581
+ match = re.search(r"under\s+(\w+\s*trust)", prompt, re.IGNORECASE)
1582
+ if match:
1583
+ bucket_name = match.group(1).replace("trust", "").strip()
1584
+ if bucket_name in ["Stability", "Development", "Relationship", "Benefit", "Vision", "Competence"]:
1585
+ specified_bucket = bucket_name
1586
+
1587
+ if content_to_save:
1588
+ handle_save_trustbuilder(content_to_save, specified_bucket)
1589
  else:
1590
+ with st.chat_message("assistant"):
1591
+ st.markdown("Please provide content to save as TrustBuilder.")
1592
+ return None
 
 
 
 
 
 
 
1593
 
1594
  # Retrieve saved TrustBuilders
1595
  elif "show my saved trustbuilders" in prompt or "find my saved trustbuilders" in prompt:
 
1611
  else:
1612
  return "You haven't saved any Brand Tonality entries yet."
1613
 
1614
+ return None #
1615
+
 
1616
  def delete_entry(category, entry_id):
1617
  try:
1618
  user_id = st.session_state["wix_user_id"]
 
1644
  break
1645
 
1646
  if not bucket:
1647
+ # Store content and prompt user for bucket
1648
  st.session_state["missing_trustbucket_content"] = content
1649
+ with st.chat_message("assistant"):
1650
+ st.markdown(
1651
+ "No Trust Bucket specified. Please indicate the Trust Bucket (e.g., Stability, Development, Relationship, Benefit, Vision, Competence)."
1652
+ )
1653
  return
1654
 
1655
  # Save TrustBuilder with detected/provided bucket
1656
  brand = st.session_state.get("brand_input_save", "Unknown")
1657
  content_to_save = f"{bucket}: Brand: {brand.strip()} | {content.strip()}"
1658
  save_content(st.session_state["wix_user_id"], content_to_save)
1659
+ with st.chat_message("assistant"):
1660
+ st.markdown(f"TrustBuilder saved under '{bucket}' Trust.")
 
1661
 
1662
 
1663
  # Function to update the message counter in a static location
 
1671
  if "used_messages" not in st.session_state:
1672
  st.session_state["used_messages"] = 0
1673
 
1674
+ if "missing_trustbucket_content" not in st.session_state:
1675
+ st.session_state["missing_trustbucket_content"] = None
1676
+
1677
  def initialize_user_session():
1678
  """
1679
  Initialize user session and ensure user data exists in Firebase.
 
1732
  if prompt:
1733
  st.session_state.chat_started = True
1734
  st.session_state.chat_history.append({"role": "user", "content": prompt})
1735
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1736
 
1737
  # Handle save commands based on the user prompt
1738
  memory_response = handle_memory_queries(prompt)
1739
  if memory_response:
1740
  with st.chat_message("assistant"):
1741
  st.markdown(memory_response)
1742
+ elif st.session_state.get("missing_trustbucket_content"):
1743
+ bucket = prompt.strip()
1744
+ valid_buckets = ["Stability", "Development", "Relationship", "Benefit", "Vision", "Competence"]
1745
+ if bucket in valid_buckets:
1746
+ content_to_save = st.session_state.pop("missing_trustbucket_content")
1747
+ handle_save_trustbuilder(content_to_save, bucket)
 
 
 
 
 
 
1748
  else:
1749
+ with st.chat_message("assistant"):
1750
+ st.markdown("Invalid Trust Bucket. Please provide a valid Trust Bucket (e.g., Stability, Development, Relationship, Benefit, Vision, Competence).")
1751
+ else:
1752
  # Generate a response with AI for general queries
1753
  with st.chat_message("user"):
1754
  st.markdown(prompt)