Spaces:
Sleeping
Sleeping
Update app.py
Browse files682 unmodified lines6836846856866876886896906918 unmodified lines7007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367372 unmodified lines7407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737746 unmodified lines781782783784785786787788789790791792793794795796797798799800682 unmodified linesst.header("TrustVault®")st.sidebar.subheader("Saved Documents")# Add custom styles for buttons and scrollable containerst.sidebar.markdown("""<style>.scrollable-container {8 unmodified lines.button-container {display: flex;justify-content: space-between;}.custom-upload-button {display: inline-block;font-size: 14px;font-weight: bold;color: white;background-color: #007bff;padding: 8px 16px;border-radius: 5px;cursor: pointer;text-align: center;border: none;}.custom-upload-button:hover {background-color: #0056b3;}.custom-delete-button {background-color: #dc3545;color: white;padding: 8px 16px;font-size: 14px;border: none;border-radius: 5px;cursor: pointer;font-weight: bold;}.custom-delete-button:hover {background-color: #a71d2a;}</style>""", unsafe_allow_html=True)# Fetch documents from Firebaseif "documents" not in st.session_state:try:2 unmodified linesexcept Exception as e:st.sidebar.error(f"Error fetching documents: {e}")st.session_state["documents"] = {}# Display saved documentssaved_docs = ""if st.session_state["documents"]:for doc_id, doc_data in st.session_state["documents"].items():doc_name = doc_data.get("content", f"Document {doc_id[:8]}")saved_docs += f"{doc_name}\n"else:saved_docs = "Save documents like your brand tonality, key phrases, or segments here and they will show here."# Scrollable text areasaved_docs_display = st.sidebar.text_area(label="",value=saved_docs,height=150,key="saved_documents_text_area",disabled=True)# File uploader and delete button in the same rowst.sidebar.markdown('<div class="button-container">', unsafe_allow_html=True)# File uploader button (customized)uploaded_file = st.file_uploader("", type=["pdf", "docx", "txt"], key="hidden_file_uploader", label_visibility="collapsed")upload_button_html = f"""<button class="custom-upload-button" onclick="document.querySelector('input[type=file]').click();">Upload</button>"""st.sidebar.markdown(upload_button_html, unsafe_allow_html=True)# Delete Buttonif st.session_state["documents"]:selected_doc_to_delete = st.selectbox(6 unmodified linestry:delete_document(st.session_state["wix_user_id"], selected_doc_to_delete)st.session_state["documents"].pop(selected_doc_to_delete)st.rerun()except Exception as e:st.sidebar.error(f"Error deleting document: {e}")st.sidebar.markdown("</div>", unsafe_allow_html=True)682 unmodified lines6836846856866876888 unmodified lines6976986997007017027037047057067072 unmodified lines7107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567576 unmodified lines764765766767768769770771772773774775776777682 unmodified linesst.header("TrustVault®")st.sidebar.markdown("""<style>.scrollable-container {8 unmodified lines.button-container {display: flex;justify-content: space-between;gap: 10px;}</style>""", unsafe_allow_html=True)# Fetch documents from Firebaseif "documents" not in st.session_state:try:2 unmodified linesexcept Exception as e:st.sidebar.error(f"Error fetching documents: {e}")st.session_state["documents"] = {}# Display saved documentssaved_docs = "\n".join([f"{doc_data.get('content', f'Document {doc_id[:8]}')}"for doc_id, doc_data in st.session_state["documents"].items()]) if st.session_state["documents"] else "Save documents like your brand tonality, key phrases, or segments here and they will show here."# Scrollable text areast.sidebar.text_area(label="",value=saved_docs,height=150,key="saved_documents_text_area",disabled=True)# File uploader and delete button in the same rowst.sidebar.markdown('<div class="button-container">', unsafe_allow_html=True)# File uploader (hidden uploader, triggered by button click)uploaded_file = st.file_uploader("", type=["pdf", "docx", "txt"], key="file_uploader", label_visibility="collapsed")if st.sidebar.button("Upload", key="upload_button"):if uploaded_file:try:file_content = convert_file_to_md(uploaded_file)if file_content:doc_id = str(uuid.uuid4())db.child("users").child(st.session_state["wix_user_id"]).child("KnowledgeBase").child(doc_id).set({"content": file_content})st.session_state["documents"][doc_id] = {"content": file_content}st.sidebar.success(f"Document '{uploaded_file.name}' uploaded successfully!")st.rerun()else:st.sidebar.warning("Failed to process the uploaded file.")except Exception as e:st.sidebar.error(f"Error uploading document: {e}")else:st.sidebar.warning("Please select a file to upload.")# Delete Buttonif st.session_state["documents"]:selected_doc_to_delete = st.selectbox(6 unmodified linestry:delete_document(st.session_state["wix_user_id"], selected_doc_to_delete)st.session_state["documents"].pop(selected_doc_to_delete)st.sidebar.success("Document deleted successfully!")st.rerun()except Exception as e:st.sidebar.error(f"Error deleting document: {e}")st.sidebar.markdown("</div>", unsafe_allow_html=True)
app.py+36-59