Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -546,6 +546,71 @@ def delete_document(user_id, doc_id):
|
|
| 546 |
except Exception as e:
|
| 547 |
st.error(f"Error deleting document: {e}")
|
| 548 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 549 |
|
| 550 |
def side():
|
| 551 |
with st.sidebar:
|
|
@@ -825,104 +890,83 @@ def side():
|
|
| 825 |
trust_builder_text = st.text_area("Type/paste Trust Builder®", key="trust_builder_text")
|
| 826 |
trust_buckets = ["Stability", "Development", "Relationship", "Benefit", "Vision", "Competence"]
|
| 827 |
selected_save_bucket = st.selectbox("Allocate to®", trust_buckets, key="save_bucket")
|
|
|
|
|
|
|
|
|
|
| 828 |
|
| 829 |
-
|
| 830 |
-
|
| 831 |
-
|
| 832 |
-
|
| 833 |
-
|
| 834 |
-
|
| 835 |
-
st.warning("Please fill all fields")
|
| 836 |
|
| 837 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 838 |
|
| 839 |
-
tooltip_css = """
|
| 840 |
-
<style>
|
| 841 |
-
.tooltip-container {
|
| 842 |
-
position: relative;
|
| 843 |
-
display: inline-block;
|
| 844 |
-
vertical-align: top;
|
| 845 |
-
margin-top: -15px;
|
| 846 |
-
}
|
| 847 |
|
| 848 |
-
.tooltip-container .tooltiptext {
|
| 849 |
-
visibility: hidden;
|
| 850 |
-
max-width: 90%; /* Tooltip width based on parent container */
|
| 851 |
-
width: auto; /* Automatically adjust width */
|
| 852 |
-
background-color: #f9f9f9;
|
| 853 |
-
color: #333;
|
| 854 |
-
text-align: left;
|
| 855 |
-
border-radius: 8px;
|
| 856 |
-
padding: 10px;
|
| 857 |
-
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1);
|
| 858 |
-
position: absolute;
|
| 859 |
-
z-index: 1000; /* Ensure tooltip is above other elements */
|
| 860 |
-
top: 100%; /* Position below the button */
|
| 861 |
-
left: 50%; /* Center horizontally */
|
| 862 |
-
transform: translateX(-50%);
|
| 863 |
-
opacity: 0;
|
| 864 |
-
transition: opacity 0.3s ease-in-out;
|
| 865 |
-
word-wrap: break-word; /* Ensure long text wraps */
|
| 866 |
-
}
|
| 867 |
-
.tooltip-container:hover .tooltiptext {
|
| 868 |
-
visibility: visible;
|
| 869 |
-
opacity: 1;
|
| 870 |
-
}
|
| 871 |
|
| 872 |
-
.tooltip-container button {
|
| 873 |
-
background-color: rgb(82, 129, 134);
|
| 874 |
-
color: white;
|
| 875 |
-
border: none;
|
| 876 |
-
padding: 8px 16px;
|
| 877 |
-
font-size: 14px;
|
| 878 |
-
border-radius: 5px;
|
| 879 |
-
cursor: pointer;
|
| 880 |
-
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.2);
|
| 881 |
-
font-family: Arial, sans-serif;
|
| 882 |
-
}
|
| 883 |
|
| 884 |
-
.tooltip-container button:hover {
|
| 885 |
-
background-color: rgb(70, 115, 119);
|
| 886 |
-
}
|
| 887 |
-
</style>
|
| 888 |
-
"""
|
| 889 |
|
| 890 |
-
|
| 891 |
-
# Inject CSS
|
| 892 |
-
st.markdown(tooltip_css, unsafe_allow_html=True)
|
| 893 |
-
|
| 894 |
-
st.markdown("""
|
| 895 |
-
<div class="tooltip-container">
|
| 896 |
-
<button>LetAI Allocate</button>
|
| 897 |
-
<span class="tooltiptext">
|
| 898 |
-
<b>Here’s how you can save your TrustBuilder®:</b><br><br>
|
| 899 |
-
1. Type your TrustBuilder® in the chat.<br>
|
| 900 |
-
2. If unsure of the TrustBucket®, ask the AI:<br>
|
| 901 |
-
<i>"Hey, which TrustBucket does this TrustBuilder® belong to?"</i><br><br>
|
| 902 |
-
3. Save it using the following format:<br>
|
| 903 |
-
<code>Save this as a TrustBuilder. [BucketName]. [TrustBuilder Text]</code><br><br>
|
| 904 |
-
Example:<br>
|
| 905 |
-
<code>Save this as a TrustBuilder. Stability. We focus on keeping and nurturing our team.</code>
|
| 906 |
-
</span>
|
| 907 |
-
</div>
|
| 908 |
-
""", unsafe_allow_html=True)
|
| 909 |
-
|
| 910 |
|
| 911 |
-
|
| 912 |
-
|
| 913 |
-
|
| 914 |
-
side()
|
| 915 |
-
if st.session_state.get("wix_user_id") and "faiss_db" not in st.session_state:
|
| 916 |
-
refresh_faiss_index()
|
| 917 |
|
| 918 |
-
def append_to_chat_input(brand, trust_text):
|
| 919 |
-
if brand.strip() and trust_text.strip():
|
| 920 |
-
appended_text = f"Brand: {brand.strip()} | TrustBuilder: {trust_text.strip()} Find the right TrustBucket"
|
| 921 |
-
st.session_state["chat_input_text"] = appended_text
|
| 922 |
-
else:
|
| 923 |
-
st.warning("Please fill both Brand and TrustBuilder fields before allocating.")
|
| 924 |
|
| 925 |
|
|
|
|
| 926 |
|
| 927 |
# Define search functions
|
| 928 |
def search_knowledge_base(query):
|
|
|
|
| 546 |
except Exception as e:
|
| 547 |
st.error(f"Error deleting document: {e}")
|
| 548 |
|
| 549 |
+
def display_popup():
|
| 550 |
+
# Custom CSS for the pop-up message
|
| 551 |
+
popup_css = """
|
| 552 |
+
<style>
|
| 553 |
+
.custom-popup {
|
| 554 |
+
background-color: #f9f9f9;
|
| 555 |
+
color: #333;
|
| 556 |
+
padding: 15px;
|
| 557 |
+
border-radius: 8px;
|
| 558 |
+
font-family: Arial, sans-serif;
|
| 559 |
+
font-size: 14px;
|
| 560 |
+
margin-top: 10px;
|
| 561 |
+
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1);
|
| 562 |
+
}
|
| 563 |
+
.custom-popup code {
|
| 564 |
+
background-color: #e1e1e1;
|
| 565 |
+
padding: 2px 4px;
|
| 566 |
+
border-radius: 4px;
|
| 567 |
+
color: #333;
|
| 568 |
+
font-family: monospace;
|
| 569 |
+
}
|
| 570 |
+
.custom-popup b {
|
| 571 |
+
color: #333;
|
| 572 |
+
}
|
| 573 |
+
.custom-popup i {
|
| 574 |
+
color: #333;
|
| 575 |
+
}
|
| 576 |
+
</style>
|
| 577 |
+
"""
|
| 578 |
+
# Inject custom CSS
|
| 579 |
+
st.markdown(popup_css, unsafe_allow_html=True)
|
| 580 |
+
# Display the pop-up message
|
| 581 |
+
st.markdown("""
|
| 582 |
+
<div class="custom-popup">
|
| 583 |
+
<b>Here’s how you can save your TrustBuilder® using Trustifier AI:</b><br><br>
|
| 584 |
+
1. Type your TrustBuilder® in the chat.<br><br>
|
| 585 |
+
2. If you're unsure of the TrustBucket®, ask the AI:<br>
|
| 586 |
+
<i>"Hey, which TrustBucket does this TrustBuilder® belong to?"</i><br><br>
|
| 587 |
+
3. Save it using the following format:<br>
|
| 588 |
+
<code>Save this as a TrustBuilder. [BucketName]. [TrustBuilder Text]</code><br><br>
|
| 589 |
+
<b>Example:</b><br>
|
| 590 |
+
<code>Save this as a TrustBuilder. Stability. We focus on keeping and nurturing our team.</code>
|
| 591 |
+
</div>
|
| 592 |
+
|
| 593 |
+
|
| 594 |
+
""", unsafe_allow_html=True)
|
| 595 |
+
|
| 596 |
+
# Initialize session state for button click
|
| 597 |
+
if 'letai_allocate_clicked' not in st.session_state:
|
| 598 |
+
st.session_state['letai_allocate_clicked'] = False
|
| 599 |
+
|
| 600 |
+
|
| 601 |
+
|
| 602 |
+
|
| 603 |
+
|
| 604 |
+
|
| 605 |
+
|
| 606 |
+
|
| 607 |
+
|
| 608 |
+
|
| 609 |
+
|
| 610 |
+
|
| 611 |
+
|
| 612 |
+
|
| 613 |
+
|
| 614 |
|
| 615 |
def side():
|
| 616 |
with st.sidebar:
|
|
|
|
| 890 |
trust_builder_text = st.text_area("Type/paste Trust Builder®", key="trust_builder_text")
|
| 891 |
trust_buckets = ["Stability", "Development", "Relationship", "Benefit", "Vision", "Competence"]
|
| 892 |
selected_save_bucket = st.selectbox("Allocate to®", trust_buckets, key="save_bucket")
|
| 893 |
+
|
| 894 |
+
col1, col2 = st.columns([1, 1]) # Adjust column widths as needed
|
| 895 |
+
with col1:
|
| 896 |
|
| 897 |
+
if st.button("Allocate", key="save_trustbuilder"):
|
| 898 |
+
if trust_builder_text.strip() and selected_save_bucket:
|
| 899 |
+
content_to_save = f"{selected_save_bucket}: Brand: {brand_save.strip()} | {trust_builder_text.strip()}"
|
| 900 |
+
save_content(st.session_state.get("wix_user_id"), content_to_save)
|
| 901 |
+
else:
|
| 902 |
+
st.warning("Please fill all fields")
|
|
|
|
| 903 |
|
| 904 |
+
with col2:
|
| 905 |
+
custom_button_css = """
|
| 906 |
+
<style>
|
| 907 |
+
.custom-button {
|
| 908 |
+
background-color: rgb(82, 129, 134);
|
| 909 |
+
color: white;
|
| 910 |
+
border: none;
|
| 911 |
+
padding: 8px 16px;
|
| 912 |
+
font-size: 14px;
|
| 913 |
+
border-radius: 5px;
|
| 914 |
+
cursor: pointer;
|
| 915 |
+
font-family: Arial, sans-serif;
|
| 916 |
+
}
|
| 917 |
+
.custom-button:hover {
|
| 918 |
+
background-color: rgb(70, 115, 119);
|
| 919 |
+
}
|
| 920 |
+
</style>
|
| 921 |
+
"""
|
| 922 |
+
st.markdown(custom_button_css, unsafe_allow_html=True)
|
| 923 |
+
|
| 924 |
+
# Create a unique ID for the button
|
| 925 |
+
import uuid
|
| 926 |
+
button_id = 'custom_button_' + str(uuid.uuid4()).replace('-', '')
|
| 927 |
+
|
| 928 |
+
# HTML and JavaScript for the custom button
|
| 929 |
+
custom_button_html = f"""
|
| 930 |
+
<button class="custom-button" id="{button_id}">LetAI Allocate</button>
|
| 931 |
+
<script>
|
| 932 |
+
const btn = document.getElementById("{button_id}");
|
| 933 |
+
btn.addEventListener("click", function() {{
|
| 934 |
+
// Send a message to Streamlit to set a session state variable
|
| 935 |
+
fetch('/_stcore/streamlit/report/session_state', {{
|
| 936 |
+
method: 'POST',
|
| 937 |
+
headers: {{
|
| 938 |
+
'Content-Type': 'application/json'
|
| 939 |
+
}},
|
| 940 |
+
body: JSON.stringify({{ 'letai_allocate_clicked': true }})
|
| 941 |
+
}}).then((response) => {{
|
| 942 |
+
window.location.reload();
|
| 943 |
+
}});
|
| 944 |
+
}});
|
| 945 |
+
</script>
|
| 946 |
+
"""
|
| 947 |
+
st.markdown(custom_button_html, unsafe_allow_html=True)
|
| 948 |
+
|
| 949 |
+
# Check if the custom button was clicked
|
| 950 |
+
if st.session_state['letai_allocate_clicked']:
|
| 951 |
+
display_popup()
|
| 952 |
+
# Reset the click state
|
| 953 |
+
st.session_state['letai_allocate_clicked'] = False
|
| 954 |
+
|
| 955 |
+
|
| 956 |
+
side()
|
| 957 |
+
if st.session_state.get("wix_user_id") and "faiss_db" not in st.session_state:
|
| 958 |
+
refresh_faiss_index()
|
| 959 |
+
|
| 960 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 961 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 962 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 963 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 964 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 965 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 966 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 967 |
|
| 968 |
|
| 969 |
+
|
| 970 |
|
| 971 |
# Define search functions
|
| 972 |
def search_knowledge_base(query):
|