Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -806,91 +806,67 @@ def main():
|
|
806 |
if st.button("π€ Run AI", key=f'run_with_ai_button_{idx}'):
|
807 |
search_glossary(json.dumps(editable_doc, indent=2))
|
808 |
|
809 |
-
|
810 |
elif selected_view == 'Clone Document':
|
811 |
-
|
812 |
st.markdown("#### Clone a document:")
|
813 |
-
|
814 |
-
# Displaying document IDs and clone buttons
|
815 |
for idx, doc in enumerate(documents_to_display):
|
816 |
st.markdown(f"##### Document ID: {doc.get('id', '')}")
|
817 |
-
|
818 |
-
clone_id = doc.get('id', '')
|
819 |
-
|
820 |
-
# Button to initiate cloning of the document
|
821 |
if st.button("π Clone Document", key=f'clone_button_{idx}'):
|
822 |
-
|
823 |
-
|
824 |
-
|
825 |
-
|
826 |
-
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
-
|
834 |
-
|
835 |
-
|
836 |
-
|
837 |
-
|
838 |
-
|
839 |
-
|
840 |
-
|
841 |
-
|
842 |
-
|
843 |
-
|
844 |
-
|
845 |
-
|
846 |
-
|
847 |
-
|
848 |
-
|
849 |
-
st.session_state.documents = list(container.query_items(
|
850 |
-
query="SELECT * FROM c ORDER BY c._ts DESC",
|
851 |
-
enable_cross_partition_query=True
|
852 |
-
))
|
853 |
-
|
854 |
elif selected_view == 'New Record':
|
855 |
-
|
856 |
-
st.markdown(Label)
|
857 |
-
|
858 |
-
if st.button("β Create New Blank Document"):
|
859 |
-
(container)
|
860 |
-
|
861 |
-
|
862 |
st.markdown("#### Create a new document:")
|
863 |
-
|
864 |
-
|
865 |
-
|
866 |
-
|
867 |
-
|
868 |
-
|
869 |
-
|
870 |
else:
|
871 |
-
st.
|
872 |
-
|
873 |
-
|
874 |
-
|
875 |
-
|
876 |
-
|
877 |
-
|
878 |
-
|
879 |
-
|
880 |
-
|
881 |
-
|
882 |
-
|
883 |
-
|
884 |
-
|
885 |
-
|
886 |
-
|
887 |
-
st.error(message)
|
888 |
-
except json.JSONDecodeError as e:
|
889 |
-
st.error(f"Invalid JSON: {str(e)} π«")
|
890 |
-
|
891 |
-
else:
|
892 |
-
st.sidebar.info("No documents found in this container. π")
|
893 |
-
|
894 |
|
895 |
|
896 |
st.subheader(f"π Container: {st.session_state.selected_container}")
|
|
|
806 |
if st.button("π€ Run AI", key=f'run_with_ai_button_{idx}'):
|
807 |
search_glossary(json.dumps(editable_doc, indent=2))
|
808 |
|
809 |
+
|
810 |
elif selected_view == 'Clone Document':
|
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 |
+
# 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 |
+
st.rerun()
|
824 |
+
if st.session_state.get('clone_mode', False):
|
825 |
+
st.markdown("#### Edit Cloned Document and Name Your Clone:")
|
826 |
+
cloned_doc_str = st.text_area("Cloned Document Content (in JSON format) - Update name please to make it unique before saving!", value=st.session_state.cloned_doc_str, height=300)
|
827 |
+
if st.button("πΎ Save Cloned Document"):
|
828 |
+
try:
|
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 |
+
except json.JSONDecodeError as e:
|
841 |
+
st.error(f"Invalid JSON: {str(e)} π«")
|
842 |
+
|
|
|
|
|
|
|
|
|
|
|
843 |
elif selected_view == 'New Record':
|
844 |
+
# π New Record
|
|
|
|
|
|
|
|
|
|
|
|
|
845 |
st.markdown("#### Create a new document:")
|
846 |
+
if st.button("π€ Insert Auto-Generated Record"):
|
847 |
+
success, message = save_or_clone_to_cosmos_db(container, query="Auto-generated", response="This is an auto-generated record.")
|
848 |
+
if success:
|
849 |
+
st.success(message)
|
850 |
+
st.rerun()
|
851 |
+
else:
|
852 |
+
st.error(message)
|
853 |
else:
|
854 |
+
new_id = st.text_input("ID", value=generate_unique_id(), key='new_id')
|
855 |
+
new_doc_str = st.text_area("Document Content (in JSON format)", value='{}', height=300)
|
856 |
+
if st.button("β Create New Document"):
|
857 |
+
try:
|
858 |
+
new_doc = json.loads(new_doc_str)
|
859 |
+
new_doc['id'] = new_id # Use the provided ID
|
860 |
+
success, message = insert_record(container, new_doc)
|
861 |
+
if success:
|
862 |
+
st.success(f"New document created with id: {new_doc['id']} π")
|
863 |
+
st.session_state.selected_document_id = new_doc['id']
|
864 |
+
# Switch to 'Show as Edit and Save' mode
|
865 |
+
st.rerun()
|
866 |
+
else:
|
867 |
+
st.error(message)
|
868 |
+
except json.JSONDecodeError as e:
|
869 |
+
st.error(f"Invalid JSON: {str(e)} π«")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
870 |
|
871 |
|
872 |
st.subheader(f"π Container: {st.session_state.selected_container}")
|