Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -807,19 +807,19 @@ def main():
|
|
| 807 |
search_glossary(json.dumps(editable_doc, indent=2))
|
| 808 |
|
| 809 |
|
| 810 |
-
elif selected_view == 'Clone
|
| 811 |
# ๐งฌ Clone Document per record
|
| 812 |
st.markdown("#### Clone a document:")
|
| 813 |
for idx, doc in enumerate(documents_to_display):
|
| 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 |
cloned_doc_str = st.text_area("Cloned Document Content (in JSON format) - Update name please to make it unique before saving!", value=cloned_doc, height=300)
|
| 822 |
-
st.code(cloned_doc_str, language="python")
|
| 823 |
|
| 824 |
st.markdown("#### Edit Cloned Document and Name Your Clone:")
|
| 825 |
if st.button("๐พ Save Cloned Document"):
|
|
@@ -833,7 +833,49 @@ def main():
|
|
| 833 |
st.rerun()
|
| 834 |
else:
|
| 835 |
st.error(message)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 836 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 837 |
elif selected_view == 'New Record':
|
| 838 |
# ๐ New Record
|
| 839 |
st.markdown("#### Create a new document:")
|
|
|
|
| 807 |
search_glossary(json.dumps(editable_doc, indent=2))
|
| 808 |
|
| 809 |
|
| 810 |
+
elif selected_view == 'Clone Document2':
|
| 811 |
# ๐งฌ Clone Document per record
|
| 812 |
st.markdown("#### Clone a document:")
|
| 813 |
for idx, doc in enumerate(documents_to_display):
|
| 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 |
+
st.code(cloned_doc, )
|
| 820 |
cloned_doc['id'] = generate_unique_id()
|
| 821 |
cloned_doc['name'] = generate_unique_id()
|
| 822 |
cloned_doc_str = st.text_area("Cloned Document Content (in JSON format) - Update name please to make it unique before saving!", value=cloned_doc, height=300)
|
|
|
|
| 823 |
|
| 824 |
st.markdown("#### Edit Cloned Document and Name Your Clone:")
|
| 825 |
if st.button("๐พ Save Cloned Document"):
|
|
|
|
| 833 |
st.rerun()
|
| 834 |
else:
|
| 835 |
st.error(message)
|
| 836 |
+
|
| 837 |
+
elif selected_view == 'Clone Document':
|
| 838 |
+
# ๐งฌ Clone Document per record
|
| 839 |
+
st.markdown("#### Clone a document:")
|
| 840 |
+
|
| 841 |
+
for idx, doc in enumerate(documents_to_display):
|
| 842 |
+
st.markdown(f"##### Document ID: {doc.get('id', '')}")
|
| 843 |
+
|
| 844 |
+
if st.button("๐ Clone Document", key=f'clone_button_{idx}'):
|
| 845 |
+
cloned_doc = doc.copy()
|
| 846 |
|
| 847 |
+
# Generate new unique IDs for both 'id' and 'name'
|
| 848 |
+
cloned_doc['id'] = generate_unique_id()
|
| 849 |
+
cloned_doc['name'] = generate_unique_id()
|
| 850 |
+
|
| 851 |
+
# Display the cloned document in JSON format with a prompt to edit
|
| 852 |
+
cloned_doc_str = st.text_area("Cloned Document Content (in JSON format) - You can edit before saving!",
|
| 853 |
+
value=str(cloned_doc), height=300)
|
| 854 |
+
|
| 855 |
+
st.markdown("#### Edit Cloned Document and Name Your Clone:")
|
| 856 |
+
|
| 857 |
+
# Allow user to save the cloned document
|
| 858 |
+
if st.button("๐พ Save Cloned Document"):
|
| 859 |
+
# Convert the string back to dictionary (if edited)
|
| 860 |
+
try:
|
| 861 |
+
# Assuming that cloned_doc_str will be valid JSON
|
| 862 |
+
cloned_doc = json.loads(cloned_doc_str)
|
| 863 |
+
success, message = insert_record(container, cloned_doc)
|
| 864 |
+
|
| 865 |
+
if success:
|
| 866 |
+
st.success(f"Cloned document saved with id: {cloned_doc['id']} ๐")
|
| 867 |
+
st.session_state.selected_document_id = cloned_doc['id']
|
| 868 |
+
st.session_state.clone_mode = False
|
| 869 |
+
st.session_state.cloned_doc = None
|
| 870 |
+
st.session_state.cloned_doc_str = ''
|
| 871 |
+
st.rerun()
|
| 872 |
+
else:
|
| 873 |
+
st.error(message)
|
| 874 |
+
except json.JSONDecodeError as e:
|
| 875 |
+
st.error(f"Error decoding the document. Please ensure it's valid JSON: {e}")
|
| 876 |
+
|
| 877 |
+
|
| 878 |
+
|
| 879 |
elif selected_view == 'New Record':
|
| 880 |
# ๐ New Record
|
| 881 |
st.markdown("#### Create a new document:")
|