awacke1 commited on
Commit
94c6cf0
Β·
verified Β·
1 Parent(s): 9a34eb0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -62
app.py CHANGED
@@ -809,69 +809,69 @@ def main():
809
  else:
810
  st.error("Failed to clone document. Please try again.")
811
 
812
-
813
- elif selected_view == 'Clone Document':
814
- st.markdown("# 🧬 Clone functionality - Copy wisely, paste precisely")
815
- st.markdown("#### Clone a document:")
816
-
817
- # Displaying document IDs and clone buttons
818
- for idx, doc in enumerate(documents_to_display):
819
- st.markdown(f"##### Document ID: {doc.get('id', '')}")
820
-
821
- # Button to initiate cloning of the document
822
- if st.button("πŸ“„ Clone Document", key=f'clone_button_{idx}'):
823
- with st.spinner("Cloning document..."):
824
- try:
825
- # Copy the document and reset system-managed fields
826
- cloned_doc = doc.copy()
827
- cloned_doc['id'] = generate_unique_id() # Generate new unique ID
828
- cloned_doc['createdAt'] = datetime.utcnow().isoformat() # Set new creation time
829
- cloned_doc['_rid'] = None # Clear system-managed fields
830
- cloned_doc['_self'] = None
831
- cloned_doc['_etag'] = None
832
- cloned_doc['_attachments'] = None
833
- cloned_doc['_ts'] = None
834
-
835
- # Save the cloned document
836
- response = container.create_item(body=cloned_doc)
837
- st.success(f"Cloned document saved successfully with ID: {cloned_doc['id']} πŸŽ‰")
838
-
839
- # Refresh session state documents to show the new cloned document
840
- st.session_state.documents = list(container.query_items(
841
- query="SELECT * FROM c ORDER BY c._ts DESC",
842
- enable_cross_partition_query=True
843
- ))
844
-
845
- except exceptions.CosmosHttpResponseError as e:
846
- st.error(f"HTTP error occurred: {str(e)} 🚨")
847
- except Exception as e:
848
- st.error(f"An unexpected error occurred: {str(e)} 😱")
849
-
850
- # If clone mode is activated, allow user to edit the cloned document
851
- if st.session_state.get('clone_mode', False):
852
- st.markdown("#### Edit Cloned Document and Name Your Clone:")
853
- cloned_doc_str = st.text_area(
854
- "Cloned Document Content (in JSON format) - Update name before saving!",
855
- value=st.session_state.cloned_doc_str,
856
- height=300
857
- )
858
-
859
- # Save the edited cloned document
860
- if st.button("πŸ’Ύ Save Cloned Document"):
861
  try:
862
- new_doc = json.loads(cloned_doc_str)
863
- success, message = insert_record(container, new_doc)
864
- if success:
865
- st.success(f"Cloned document saved with id: {new_doc['id']} πŸŽ‰")
866
- st.session_state.selected_document_id = new_doc['id']
867
- st.session_state.clone_mode = False
868
- st.session_state.cloned_doc = None
869
- st.session_state.cloned_doc_str = ''
870
- st.rerun()
871
- else:
872
- st.error(message)
873
- except json.JSONDecodeError as e:
874
- st.error(f"Invalid JSON: {str(e)} 🚫")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
875
 
876
 
877
 
 
809
  else:
810
  st.error("Failed to clone document. Please try again.")
811
 
812
+
813
+ elif selected_view == 'Clone Document':
814
+ st.markdown("# 🧬 Clone functionality - Copy wisely, paste precisely")
815
+ st.markdown("#### Clone a document:")
816
+
817
+ # Displaying document IDs and clone buttons
818
+ for idx, doc in enumerate(documents_to_display):
819
+ st.markdown(f"##### Document ID: {doc.get('id', '')}")
820
+
821
+ # Button to initiate cloning of the document
822
+ if st.button("πŸ“„ Clone Document", key=f'clone_button_{idx}'):
823
+ with st.spinner("Cloning document..."):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
824
  try:
825
+ # Copy the document and reset system-managed fields
826
+ cloned_doc = doc.copy()
827
+ cloned_doc['id'] = generate_unique_id() # Generate new unique ID
828
+ cloned_doc['createdAt'] = datetime.utcnow().isoformat() # Set new creation time
829
+ cloned_doc['_rid'] = None # Clear system-managed fields
830
+ cloned_doc['_self'] = None
831
+ cloned_doc['_etag'] = None
832
+ cloned_doc['_attachments'] = None
833
+ cloned_doc['_ts'] = None
834
+
835
+ # Save the cloned document
836
+ response = container.create_item(body=cloned_doc)
837
+ st.success(f"Cloned document saved successfully with ID: {cloned_doc['id']} πŸŽ‰")
838
+
839
+ # Refresh session state documents to show the new cloned document
840
+ st.session_state.documents = list(container.query_items(
841
+ query="SELECT * FROM c ORDER BY c._ts DESC",
842
+ enable_cross_partition_query=True
843
+ ))
844
+
845
+ except exceptions.CosmosHttpResponseError as e:
846
+ st.error(f"HTTP error occurred: {str(e)} 🚨")
847
+ except Exception as e:
848
+ st.error(f"An unexpected error occurred: {str(e)} 😱")
849
+
850
+ # If clone mode is activated, allow user to edit the cloned document
851
+ if st.session_state.get('clone_mode', False):
852
+ st.markdown("#### Edit Cloned Document and Name Your Clone:")
853
+ cloned_doc_str = st.text_area(
854
+ "Cloned Document Content (in JSON format) - Update name before saving!",
855
+ value=st.session_state.cloned_doc_str,
856
+ height=300
857
+ )
858
+
859
+ # Save the edited cloned document
860
+ if st.button("πŸ’Ύ Save Cloned Document"):
861
+ try:
862
+ new_doc = json.loads(cloned_doc_str)
863
+ success, message = insert_record(container, new_doc)
864
+ if success:
865
+ st.success(f"Cloned document saved with id: {new_doc['id']} πŸŽ‰")
866
+ st.session_state.selected_document_id = new_doc['id']
867
+ st.session_state.clone_mode = False
868
+ st.session_state.cloned_doc = None
869
+ st.session_state.cloned_doc_str = ''
870
+ st.rerun()
871
+ else:
872
+ st.error(message)
873
+ except json.JSONDecodeError as e:
874
+ st.error(f"Invalid JSON: {str(e)} 🚫")
875
 
876
 
877