Spaces:
Running
Running
Update app.py
Browse files
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 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
-
new_doc['id']
|
834 |
-
|
835 |
-
|
836 |
-
|
837 |
-
|
838 |
-
|
839 |
-
|
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
|