Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -683,9 +683,6 @@ def side():
|
|
| 683 |
|
| 684 |
|
| 685 |
st.header("TrustVault®")
|
| 686 |
-
st.sidebar.subheader("Saved Documents")
|
| 687 |
-
|
| 688 |
-
# Add custom styles for buttons and scrollable container
|
| 689 |
st.sidebar.markdown("""
|
| 690 |
<style>
|
| 691 |
.scrollable-container {
|
|
@@ -700,38 +697,11 @@ def side():
|
|
| 700 |
.button-container {
|
| 701 |
display: flex;
|
| 702 |
justify-content: space-between;
|
| 703 |
-
|
| 704 |
-
.custom-upload-button {
|
| 705 |
-
display: inline-block;
|
| 706 |
-
font-size: 14px;
|
| 707 |
-
font-weight: bold;
|
| 708 |
-
color: white;
|
| 709 |
-
background-color: #007bff;
|
| 710 |
-
padding: 8px 16px;
|
| 711 |
-
border-radius: 5px;
|
| 712 |
-
cursor: pointer;
|
| 713 |
-
text-align: center;
|
| 714 |
-
border: none;
|
| 715 |
-
}
|
| 716 |
-
.custom-upload-button:hover {
|
| 717 |
-
background-color: #0056b3;
|
| 718 |
-
}
|
| 719 |
-
.custom-delete-button {
|
| 720 |
-
background-color: #dc3545;
|
| 721 |
-
color: white;
|
| 722 |
-
padding: 8px 16px;
|
| 723 |
-
font-size: 14px;
|
| 724 |
-
border: none;
|
| 725 |
-
border-radius: 5px;
|
| 726 |
-
cursor: pointer;
|
| 727 |
-
font-weight: bold;
|
| 728 |
-
}
|
| 729 |
-
.custom-delete-button:hover {
|
| 730 |
-
background-color: #a71d2a;
|
| 731 |
}
|
| 732 |
</style>
|
| 733 |
""", unsafe_allow_html=True)
|
| 734 |
-
|
| 735 |
# Fetch documents from Firebase
|
| 736 |
if "documents" not in st.session_state:
|
| 737 |
try:
|
|
@@ -740,35 +710,48 @@ def side():
|
|
| 740 |
except Exception as e:
|
| 741 |
st.sidebar.error(f"Error fetching documents: {e}")
|
| 742 |
st.session_state["documents"] = {}
|
| 743 |
-
|
| 744 |
# Display saved documents
|
| 745 |
-
saved_docs = ""
|
| 746 |
-
|
| 747 |
-
|
| 748 |
-
|
| 749 |
-
|
| 750 |
-
else
|
| 751 |
-
|
| 752 |
-
|
| 753 |
# Scrollable text area
|
| 754 |
-
|
| 755 |
label="",
|
| 756 |
value=saved_docs,
|
| 757 |
height=150,
|
| 758 |
key="saved_documents_text_area",
|
| 759 |
disabled=True
|
| 760 |
)
|
| 761 |
-
|
| 762 |
# File uploader and delete button in the same row
|
| 763 |
st.sidebar.markdown('<div class="button-container">', unsafe_allow_html=True)
|
| 764 |
-
|
| 765 |
-
# File uploader button
|
| 766 |
-
uploaded_file = st.file_uploader("", type=["pdf", "docx", "txt"], key="
|
| 767 |
-
|
| 768 |
-
|
| 769 |
-
|
| 770 |
-
|
| 771 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 772 |
# Delete Button
|
| 773 |
if st.session_state["documents"]:
|
| 774 |
selected_doc_to_delete = st.selectbox(
|
|
@@ -781,20 +764,14 @@ def side():
|
|
| 781 |
try:
|
| 782 |
delete_document(st.session_state["wix_user_id"], selected_doc_to_delete)
|
| 783 |
st.session_state["documents"].pop(selected_doc_to_delete)
|
|
|
|
| 784 |
st.rerun()
|
| 785 |
except Exception as e:
|
| 786 |
st.sidebar.error(f"Error deleting document: {e}")
|
| 787 |
-
|
| 788 |
st.sidebar.markdown("</div>", unsafe_allow_html=True)
|
| 789 |
|
| 790 |
|
| 791 |
-
|
| 792 |
-
|
| 793 |
-
|
| 794 |
-
|
| 795 |
-
|
| 796 |
-
|
| 797 |
-
|
| 798 |
|
| 799 |
|
| 800 |
|
|
|
|
| 683 |
|
| 684 |
|
| 685 |
st.header("TrustVault®")
|
|
|
|
|
|
|
|
|
|
| 686 |
st.sidebar.markdown("""
|
| 687 |
<style>
|
| 688 |
.scrollable-container {
|
|
|
|
| 697 |
.button-container {
|
| 698 |
display: flex;
|
| 699 |
justify-content: space-between;
|
| 700 |
+
gap: 10px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 701 |
}
|
| 702 |
</style>
|
| 703 |
""", unsafe_allow_html=True)
|
| 704 |
+
|
| 705 |
# Fetch documents from Firebase
|
| 706 |
if "documents" not in st.session_state:
|
| 707 |
try:
|
|
|
|
| 710 |
except Exception as e:
|
| 711 |
st.sidebar.error(f"Error fetching documents: {e}")
|
| 712 |
st.session_state["documents"] = {}
|
| 713 |
+
|
| 714 |
# Display saved documents
|
| 715 |
+
saved_docs = "\n".join(
|
| 716 |
+
[
|
| 717 |
+
f"{doc_data.get('content', f'Document {doc_id[:8]}')}"
|
| 718 |
+
for doc_id, doc_data in st.session_state["documents"].items()
|
| 719 |
+
]
|
| 720 |
+
) if st.session_state["documents"] else "Save documents like your brand tonality, key phrases, or segments here and they will show here."
|
| 721 |
+
|
|
|
|
| 722 |
# Scrollable text area
|
| 723 |
+
st.sidebar.text_area(
|
| 724 |
label="",
|
| 725 |
value=saved_docs,
|
| 726 |
height=150,
|
| 727 |
key="saved_documents_text_area",
|
| 728 |
disabled=True
|
| 729 |
)
|
| 730 |
+
|
| 731 |
# File uploader and delete button in the same row
|
| 732 |
st.sidebar.markdown('<div class="button-container">', unsafe_allow_html=True)
|
| 733 |
+
|
| 734 |
+
# File uploader (hidden uploader, triggered by button click)
|
| 735 |
+
uploaded_file = st.file_uploader("", type=["pdf", "docx", "txt"], key="file_uploader", label_visibility="collapsed")
|
| 736 |
+
if st.sidebar.button("Upload", key="upload_button"):
|
| 737 |
+
if uploaded_file:
|
| 738 |
+
try:
|
| 739 |
+
file_content = convert_file_to_md(uploaded_file)
|
| 740 |
+
if file_content:
|
| 741 |
+
doc_id = str(uuid.uuid4())
|
| 742 |
+
db.child("users").child(st.session_state["wix_user_id"]).child("KnowledgeBase").child(doc_id).set(
|
| 743 |
+
{"content": file_content}
|
| 744 |
+
)
|
| 745 |
+
st.session_state["documents"][doc_id] = {"content": file_content}
|
| 746 |
+
st.sidebar.success(f"Document '{uploaded_file.name}' uploaded successfully!")
|
| 747 |
+
st.rerun()
|
| 748 |
+
else:
|
| 749 |
+
st.sidebar.warning("Failed to process the uploaded file.")
|
| 750 |
+
except Exception as e:
|
| 751 |
+
st.sidebar.error(f"Error uploading document: {e}")
|
| 752 |
+
else:
|
| 753 |
+
st.sidebar.warning("Please select a file to upload.")
|
| 754 |
+
|
| 755 |
# Delete Button
|
| 756 |
if st.session_state["documents"]:
|
| 757 |
selected_doc_to_delete = st.selectbox(
|
|
|
|
| 764 |
try:
|
| 765 |
delete_document(st.session_state["wix_user_id"], selected_doc_to_delete)
|
| 766 |
st.session_state["documents"].pop(selected_doc_to_delete)
|
| 767 |
+
st.sidebar.success("Document deleted successfully!")
|
| 768 |
st.rerun()
|
| 769 |
except Exception as e:
|
| 770 |
st.sidebar.error(f"Error deleting document: {e}")
|
| 771 |
+
|
| 772 |
st.sidebar.markdown("</div>", unsafe_allow_html=True)
|
| 773 |
|
| 774 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 775 |
|
| 776 |
|
| 777 |
|