Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -699,6 +699,24 @@ def side():
|
|
| 699 |
justify-content: space-between;
|
| 700 |
margin-top: 10px;
|
| 701 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 702 |
</style>
|
| 703 |
""", unsafe_allow_html=True)
|
| 704 |
|
|
@@ -710,7 +728,7 @@ def side():
|
|
| 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 |
|
| 716 |
saved_docs = ""
|
|
@@ -730,33 +748,38 @@ def side():
|
|
| 730 |
disabled=True # To prevent editing of the text area
|
| 731 |
)
|
| 732 |
|
| 733 |
-
#
|
| 734 |
-
|
| 735 |
|
| 736 |
-
|
| 737 |
-
|
| 738 |
-
|
| 739 |
-
|
| 740 |
-
|
| 741 |
-
|
| 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 |
-
|
| 756 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
)
|
|
@@ -769,6 +792,21 @@ def side():
|
|
| 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®")
|
| 774 |
|
|
|
|
| 699 |
justify-content: space-between;
|
| 700 |
margin-top: 10px;
|
| 701 |
}
|
| 702 |
+
.custom-upload-button {
|
| 703 |
+
display: inline-block;
|
| 704 |
+
font-size: 14px;
|
| 705 |
+
font-weight: 600;
|
| 706 |
+
color: white;
|
| 707 |
+
background-color: #007bff;
|
| 708 |
+
padding: 8px 16px;
|
| 709 |
+
border-radius: 5px;
|
| 710 |
+
cursor: pointer;
|
| 711 |
+
text-align: center;
|
| 712 |
+
margin-right: 10px;
|
| 713 |
+
}
|
| 714 |
+
.custom-upload-button:hover {
|
| 715 |
+
background-color: #0056b3;
|
| 716 |
+
}
|
| 717 |
+
.hidden-file-uploader {
|
| 718 |
+
display: none;
|
| 719 |
+
}
|
| 720 |
</style>
|
| 721 |
""", unsafe_allow_html=True)
|
| 722 |
|
|
|
|
| 728 |
except Exception as e:
|
| 729 |
st.sidebar.error(f"Error fetching documents: {e}")
|
| 730 |
st.session_state["documents"] = {}
|
| 731 |
+
|
| 732 |
st.sidebar.subheader("Saved Documents")
|
| 733 |
|
| 734 |
saved_docs = ""
|
|
|
|
| 748 |
disabled=True # To prevent editing of the text area
|
| 749 |
)
|
| 750 |
|
| 751 |
+
# Upload and Delete Buttons
|
| 752 |
+
st.sidebar.markdown('<div class="button-container">', unsafe_allow_html=True)
|
| 753 |
|
| 754 |
+
# Custom File Upload Button
|
| 755 |
+
uploaded_file = st.file_uploader("", key="hidden_file_uploader", label_visibility="collapsed")
|
| 756 |
+
upload_button_html = f"""
|
| 757 |
+
<label for="hidden_file_uploader" class="custom-upload-button">Upload</label>
|
| 758 |
+
"""
|
| 759 |
+
st.sidebar.markdown(upload_button_html, unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 760 |
|
| 761 |
+
if uploaded_file:
|
| 762 |
+
try:
|
| 763 |
+
file_content = convert_file_to_md(uploaded_file)
|
| 764 |
+
if file_content:
|
| 765 |
+
doc_id = str(uuid.uuid4())
|
| 766 |
+
db.child("users").child(st.session_state["wix_user_id"]).child("KnowledgeBase").child(doc_id).set(
|
| 767 |
+
{"content": file_content}
|
| 768 |
+
)
|
| 769 |
+
st.session_state["documents"][doc_id] = {"content": file_content}
|
| 770 |
+
st.sidebar.success(f"Document '{uploaded_file.name}' uploaded successfully!")
|
| 771 |
+
st.experimental_rerun()
|
| 772 |
+
else:
|
| 773 |
+
st.sidebar.warning("Failed to process the uploaded file.")
|
| 774 |
+
except Exception as e:
|
| 775 |
+
st.sidebar.error(f"Error uploading document: {e}")
|
| 776 |
+
|
| 777 |
+
# Delete Button and Selector
|
| 778 |
+
if st.session_state["documents"]:
|
| 779 |
+
with st.sidebar:
|
| 780 |
selected_doc_to_delete = st.selectbox(
|
| 781 |
+
"Select document to delete",
|
| 782 |
+
options=list(st.session_state["documents"].keys()),
|
| 783 |
format_func=lambda x: st.session_state["documents"][x].get("content", f"Document {x}"),
|
| 784 |
key="delete_doc_selector"
|
| 785 |
)
|
|
|
|
| 792 |
except Exception as e:
|
| 793 |
st.sidebar.error(f"Error deleting document: {e}")
|
| 794 |
|
| 795 |
+
st.sidebar.markdown('</div>', unsafe_allow_html=True)
|
| 796 |
+
|
| 797 |
+
|
| 798 |
+
|
| 799 |
+
|
| 800 |
+
|
| 801 |
+
|
| 802 |
+
|
| 803 |
+
|
| 804 |
+
|
| 805 |
+
|
| 806 |
+
|
| 807 |
+
|
| 808 |
+
|
| 809 |
+
|
| 810 |
# Show Trust Builders Section
|
| 811 |
st.subheader("Show My TrustBuilders®")
|
| 812 |
|