Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -554,7 +554,6 @@ def delete_document(user_id, doc_id):
|
|
| 554 |
st.error(f"Error deleting document: {e}")
|
| 555 |
|
| 556 |
|
| 557 |
-
|
| 558 |
def side():
|
| 559 |
with st.sidebar:
|
| 560 |
|
|
@@ -681,7 +680,7 @@ def side():
|
|
| 681 |
)
|
| 682 |
st.markdown("For detailed descriptions, visit [Academy](https://www.trustifier.ai/account/academy)")
|
| 683 |
|
| 684 |
-
|
| 685 |
|
| 686 |
st.header("TrustVault®")
|
| 687 |
st.sidebar.markdown("""
|
|
@@ -704,61 +703,75 @@ def side():
|
|
| 704 |
""", unsafe_allow_html=True)
|
| 705 |
|
| 706 |
# Saved Documents Section
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 707 |
st.sidebar.subheader("Saved Documents")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 708 |
|
| 709 |
-
#
|
| 710 |
-
doc_texts = ""
|
| 711 |
-
try:
|
| 712 |
-
docs = db.child("users").child(st.session_state["wix_user_id"]).child("KnowledgeBase").get().val()
|
| 713 |
-
if docs:
|
| 714 |
-
for doc_id, doc_data in docs.items():
|
| 715 |
-
doc_name = doc_data.get("content", f"Document {doc_id[:8]}")
|
| 716 |
-
doc_texts += f"{doc_name}\n"
|
| 717 |
-
else:
|
| 718 |
-
doc_texts = "No saved documents found."
|
| 719 |
-
except Exception as e:
|
| 720 |
-
st.sidebar.error(f"Error fetching documents: {e}")
|
| 721 |
-
|
| 722 |
-
savedDoc = st.sidebar.text_area("", doc_texts, height=200)
|
| 723 |
-
|
| 724 |
-
# Button container for Upload and Delete actions
|
| 725 |
-
st.sidebar.markdown('<div class="button-container">', unsafe_allow_html=True)
|
| 726 |
-
|
| 727 |
-
# File uploader
|
| 728 |
uploaded_file = st.sidebar.file_uploader("", key="file_uploader", label_visibility="collapsed")
|
| 729 |
-
|
| 730 |
-
# Upload button
|
| 731 |
if st.sidebar.button("Upload", key="upload_button"):
|
| 732 |
if uploaded_file:
|
| 733 |
try:
|
| 734 |
-
# Convert and upload the file
|
| 735 |
file_content = convert_file_to_md(uploaded_file)
|
| 736 |
if file_content:
|
| 737 |
doc_id = str(uuid.uuid4())
|
| 738 |
-
db.child("users").child(st.session_state["wix_user_id"]).child("KnowledgeBase").child(doc_id).set(
|
| 739 |
-
|
| 740 |
-
|
|
|
|
|
|
|
|
|
|
| 741 |
else:
|
| 742 |
st.sidebar.warning("Failed to process the uploaded file.")
|
| 743 |
except Exception as e:
|
| 744 |
st.sidebar.error(f"Error uploading document: {e}")
|
| 745 |
-
else:
|
| 746 |
-
st.sidebar.warning("Please select a file to upload.")
|
| 747 |
|
| 748 |
-
# Delete
|
| 749 |
-
if
|
| 750 |
-
|
| 751 |
-
|
| 752 |
-
|
|
|
|
|
|
|
|
|
|
| 753 |
try:
|
| 754 |
-
|
| 755 |
-
|
| 756 |
-
|
| 757 |
-
|
| 758 |
-
st.sidebar.success("Selected documents deleted successfully!")
|
| 759 |
-
st.rerun() # Refresh the display
|
| 760 |
except Exception as e:
|
| 761 |
-
st.sidebar.error(f"Error deleting
|
| 762 |
|
| 763 |
st.sidebar.markdown('</div>', unsafe_allow_html=True)
|
| 764 |
|
|
|
|
| 554 |
st.error(f"Error deleting document: {e}")
|
| 555 |
|
| 556 |
|
|
|
|
| 557 |
def side():
|
| 558 |
with st.sidebar:
|
| 559 |
|
|
|
|
| 680 |
)
|
| 681 |
st.markdown("For detailed descriptions, visit [Academy](https://www.trustifier.ai/account/academy)")
|
| 682 |
|
| 683 |
+
|
| 684 |
|
| 685 |
st.header("TrustVault®")
|
| 686 |
st.sidebar.markdown("""
|
|
|
|
| 703 |
""", unsafe_allow_html=True)
|
| 704 |
|
| 705 |
# Saved Documents Section
|
| 706 |
+
if "documents" not in st.session_state:
|
| 707 |
+
try:
|
| 708 |
+
docs = db.child("users").child(st.session_state["wix_user_id"]).child("KnowledgeBase").get().val()
|
| 709 |
+
st.session_state["documents"] = docs if docs else {}
|
| 710 |
+
except Exception as e:
|
| 711 |
+
st.sidebar.error(f"Error fetching documents: {e}")
|
| 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"- {doc_name}\n"
|
| 720 |
+
else:
|
| 721 |
+
saved_docs = "Save documents like your brand tonality, key phrases, or segments here and they will show here."
|
| 722 |
+
# Scrollable text area
|
| 723 |
+
st.sidebar.markdown(
|
| 724 |
+
f"""
|
| 725 |
+
<style>
|
| 726 |
+
.scrollable-text-area {{
|
| 727 |
+
max-height: 150px;
|
| 728 |
+
overflow-y: auto;
|
| 729 |
+
border: 1px solid gray;
|
| 730 |
+
border-radius: 5px;
|
| 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 |
uploaded_file = st.sidebar.file_uploader("", key="file_uploader", label_visibility="collapsed")
|
|
|
|
|
|
|
| 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.experimental_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 |
+
# Delete documents functionality
|
| 761 |
+
if st.session_state["documents"]:
|
| 762 |
+
selected_doc_to_delete = st.sidebar.selectbox(
|
| 763 |
+
"Select document to delete",
|
| 764 |
+
options=list(st.session_state["documents"].keys()),
|
| 765 |
+
format_func=lambda x: st.session_state["documents"][x].get("content", f"Document {x}")
|
| 766 |
+
)
|
| 767 |
+
if st.sidebar.button("Delete", key="delete_button"):
|
| 768 |
try:
|
| 769 |
+
db.child("users").child(st.session_state["wix_user_id"]).child("KnowledgeBase").child(selected_doc_to_delete).remove()
|
| 770 |
+
st.session_state["documents"].pop(selected_doc_to_delete)
|
| 771 |
+
st.sidebar.success("Document deleted successfully!")
|
| 772 |
+
st.experimental_rerun()
|
|
|
|
|
|
|
| 773 |
except Exception as e:
|
| 774 |
+
st.sidebar.error(f"Error deleting document: {e}")
|
| 775 |
|
| 776 |
st.sidebar.markdown('</div>', unsafe_allow_html=True)
|
| 777 |
|