Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -712,68 +712,62 @@ def side():
|
|
| 712 |
st.session_state["documents"] = {}
|
| 713 |
|
| 714 |
st.sidebar.subheader("Saved Documents")
|
|
|
|
| 715 |
saved_docs = ""
|
| 716 |
if st.session_state["documents"]:
|
| 717 |
for doc_id, doc_data in st.session_state["documents"].items():
|
| 718 |
doc_name = doc_data.get("content", f"Document {doc_id[:8]}")
|
| 719 |
-
saved_docs += f"
|
| 720 |
else:
|
| 721 |
saved_docs = "Save documents like your brand tonality, key phrases, or segments here and they will show here."
|
| 722 |
-
|
| 723 |
-
|
| 724 |
-
|
| 725 |
-
|
| 726 |
-
|
| 727 |
-
|
| 728 |
-
|
| 729 |
-
|
| 730 |
-
|
| 731 |
-
background-color: #f9f9f9;
|
| 732 |
-
padding: 10px;
|
| 733 |
-
font-size: 14px;
|
| 734 |
-
color: #555;
|
| 735 |
-
}}
|
| 736 |
-
</style>
|
| 737 |
-
<div class="scrollable-text-area">{saved_docs}</div>
|
| 738 |
-
""",
|
| 739 |
-
unsafe_allow_html=True,)
|
| 740 |
|
| 741 |
# File uploader and delete buttons
|
| 742 |
-
|
| 743 |
-
if st.sidebar.button("Upload", key="upload_button"):
|
| 744 |
-
if uploaded_file:
|
| 745 |
-
try:
|
| 746 |
-
file_content = convert_file_to_md(uploaded_file)
|
| 747 |
-
if file_content:
|
| 748 |
-
doc_id = str(uuid.uuid4())
|
| 749 |
-
db.child("users").child(st.session_state["wix_user_id"]).child("KnowledgeBase").child(doc_id).set(
|
| 750 |
-
{"content": file_content}
|
| 751 |
-
)
|
| 752 |
-
st.session_state["documents"][doc_id] = {"content": file_content}
|
| 753 |
-
st.sidebar.success(f"Document '{uploaded_file.name}' uploaded successfully!")
|
| 754 |
-
st.rerun()
|
| 755 |
-
else:
|
| 756 |
-
st.sidebar.warning("Failed to process the uploaded file.")
|
| 757 |
-
except Exception as e:
|
| 758 |
-
st.sidebar.error(f"Error uploading document: {e}")
|
| 759 |
|
| 760 |
-
|
| 761 |
-
|
| 762 |
-
|
| 763 |
-
|
| 764 |
-
|
| 765 |
-
|
| 766 |
-
|
| 767 |
-
|
| 768 |
-
|
| 769 |
-
|
| 770 |
-
|
| 771 |
-
|
| 772 |
-
|
| 773 |
-
|
| 774 |
-
|
|
|
|
|
|
|
|
|
|
| 775 |
|
| 776 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 777 |
|
| 778 |
# Show Trust Builders Section
|
| 779 |
st.subheader("Show My TrustBuilders®")
|
|
|
|
| 712 |
st.session_state["documents"] = {}
|
| 713 |
|
| 714 |
st.sidebar.subheader("Saved Documents")
|
| 715 |
+
|
| 716 |
saved_docs = ""
|
| 717 |
if st.session_state["documents"]:
|
| 718 |
for doc_id, doc_data in st.session_state["documents"].items():
|
| 719 |
doc_name = doc_data.get("content", f"Document {doc_id[:8]}")
|
| 720 |
+
saved_docs += f"{doc_name}\n"
|
| 721 |
else:
|
| 722 |
saved_docs = "Save documents like your brand tonality, key phrases, or segments here and they will show here."
|
| 723 |
+
|
| 724 |
+
# Display documents inside a text area (scrollable)
|
| 725 |
+
saved_docs_display = st.sidebar.text_area(
|
| 726 |
+
label="",
|
| 727 |
+
value=saved_docs,
|
| 728 |
+
height=150,
|
| 729 |
+
key="saved_documents_text_area",
|
| 730 |
+
disabled=True # To prevent editing of the text area
|
| 731 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 732 |
|
| 733 |
# File uploader and delete buttons
|
| 734 |
+
col1, col2 = st.sidebar.columns(2, gap="small")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 735 |
|
| 736 |
+
with col1:
|
| 737 |
+
uploaded_file = st.file_uploader("", key="file_uploader", label_visibility="collapsed")
|
| 738 |
+
if st.button("Upload", key="upload_button"):
|
| 739 |
+
if uploaded_file:
|
| 740 |
+
try:
|
| 741 |
+
file_content = convert_file_to_md(uploaded_file)
|
| 742 |
+
if file_content:
|
| 743 |
+
doc_id = str(uuid.uuid4())
|
| 744 |
+
db.child("users").child(st.session_state["wix_user_id"]).child("KnowledgeBase").child(doc_id).set(
|
| 745 |
+
{"content": file_content}
|
| 746 |
+
)
|
| 747 |
+
st.session_state["documents"][doc_id] = {"content": file_content}
|
| 748 |
+
st.sidebar.success(f"Document '{uploaded_file.name}' uploaded successfully!")
|
| 749 |
+
st.experimental_rerun()
|
| 750 |
+
else:
|
| 751 |
+
st.sidebar.warning("Failed to process the uploaded file.")
|
| 752 |
+
except Exception as e:
|
| 753 |
+
st.sidebar.error(f"Error uploading document: {e}")
|
| 754 |
|
| 755 |
+
with col2:
|
| 756 |
+
if st.session_state["documents"]:
|
| 757 |
+
selected_doc_to_delete = st.selectbox(
|
| 758 |
+
"Select document to delete",
|
| 759 |
+
options=list(st.session_state["documents"].keys()),
|
| 760 |
+
format_func=lambda x: st.session_state["documents"][x].get("content", f"Document {x}"),
|
| 761 |
+
key="delete_doc_selector"
|
| 762 |
+
)
|
| 763 |
+
if st.button("Delete", key="delete_button"):
|
| 764 |
+
try:
|
| 765 |
+
db.child("users").child(st.session_state["wix_user_id"]).child("KnowledgeBase").child(selected_doc_to_delete).remove()
|
| 766 |
+
st.session_state["documents"].pop(selected_doc_to_delete)
|
| 767 |
+
st.sidebar.success("Document deleted successfully!")
|
| 768 |
+
st.experimental_rerun()
|
| 769 |
+
except Exception as e:
|
| 770 |
+
st.sidebar.error(f"Error deleting document: {e}")
|
| 771 |
|
| 772 |
# Show Trust Builders Section
|
| 773 |
st.subheader("Show My TrustBuilders®")
|