awacke1 commited on
Commit
2c78a83
ยท
verified ยท
1 Parent(s): 6647b6e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -22
app.py CHANGED
@@ -814,37 +814,29 @@ def main():
814
  st.markdown(f"##### Document ID: {doc.get('id', '')}")
815
  if st.button("๐Ÿ“„ Clone Document", key=f'clone_button_{idx}'):
816
  cloned_doc = doc.copy()
 
817
  # Generate a unique ID
818
  cloned_doc['id'] = generate_unique_id()
819
  cloned_doc['name'] = generate_unique_id()
820
  st.session_state.cloned_doc = cloned_doc
821
  st.session_state.cloned_doc_str = json.dumps(cloned_doc, indent=2)
822
- st.session_state.clone_mode = True
823
-
824
- new_doc = json.loads(cloned_doc_str)
825
  cloned_doc_str = st.text_area("Cloned Document Content (in JSON format) - Update name please to make it unique before saving!", value=new_doc, height=300)
826
 
827
  st.markdown("#### Edit Cloned Document and Name Your Clone:")
828
  if st.button("๐Ÿ’พ Save Cloned Document"):
829
- try:
830
- new_doc = json.loads(cloned_doc_str)
831
-
832
- # Generate new name and id
833
- new_doc['id'] = generate_unique_id()
834
- new_doc['name'] = generate_unique_id()
835
-
836
- success, message = insert_record(container, new_doc)
837
- if success:
838
- st.success(f"Cloned document saved with id: {new_doc['id']} ๐ŸŽ‰")
839
- st.session_state.selected_document_id = new_doc['id']
840
- st.session_state.clone_mode = False
841
- st.session_state.cloned_doc = None
842
- st.session_state.cloned_doc_str = ''
843
- st.rerun()
844
- else:
845
- st.error(message)
846
- except json.JSONDecodeError as e:
847
- st.error(f"Invalid JSON: {str(e)} ๐Ÿšซ")
848
 
849
  elif selected_view == 'New Record':
850
  # ๐Ÿ†• New Record
 
814
  st.markdown(f"##### Document ID: {doc.get('id', '')}")
815
  if st.button("๐Ÿ“„ Clone Document", key=f'clone_button_{idx}'):
816
  cloned_doc = doc.copy()
817
+
818
  # Generate a unique ID
819
  cloned_doc['id'] = generate_unique_id()
820
  cloned_doc['name'] = generate_unique_id()
821
  st.session_state.cloned_doc = cloned_doc
822
  st.session_state.cloned_doc_str = json.dumps(cloned_doc, indent=2)
823
+ st.session_state.clone_mode = True
824
+ new_doc = json.loads(st.session_state.cloned_doc_str)
 
825
  cloned_doc_str = st.text_area("Cloned Document Content (in JSON format) - Update name please to make it unique before saving!", value=new_doc, height=300)
826
 
827
  st.markdown("#### Edit Cloned Document and Name Your Clone:")
828
  if st.button("๐Ÿ’พ Save Cloned Document"):
829
+ new_doc = json.loads(cloned_doc_str)
830
+ success, message = insert_record(container, new_doc)
831
+ if success:
832
+ st.success(f"Cloned document saved with id: {new_doc['id']} ๐ŸŽ‰")
833
+ st.session_state.selected_document_id = new_doc['id']
834
+ st.session_state.clone_mode = False
835
+ st.session_state.cloned_doc = None
836
+ st.session_state.cloned_doc_str = ''
837
+ st.rerun()
838
+ else:
839
+ st.error(message)
 
 
 
 
 
 
 
 
840
 
841
  elif selected_view == 'New Record':
842
  # ๐Ÿ†• New Record