Spaces:
Sleeping
Sleeping
Update backup12.app.py
Browse files- backup12.app.py +128 -39
backup12.app.py
CHANGED
|
@@ -684,13 +684,100 @@ def main():
|
|
| 684 |
if st.session_state.current_index < total_docs - 1:
|
| 685 |
st.session_state.current_index += 1
|
| 686 |
st.rerun()
|
| 687 |
-
|
| 688 |
-
|
| 689 |
|
| 690 |
elif selected_view == 'Show as Code Editor':
|
| 691 |
Label = '#### 💻 Code editor view'
|
| 692 |
st.markdown(Label)
|
| 693 |
total_docs = len(documents)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 694 |
doc = documents[st.session_state.current_index]
|
| 695 |
# st.markdown(f"#### Document ID: {doc.get('id', '')}")
|
| 696 |
doc_str = st.text_area("Edit Document",
|
|
@@ -736,6 +823,8 @@ def main():
|
|
| 736 |
st.rerun()
|
| 737 |
except Exception as e:
|
| 738 |
st.error(f"Error deleting document: {str(e)}")
|
|
|
|
|
|
|
| 739 |
|
| 740 |
|
| 741 |
elif selected_view == 'Show as Run AI':
|
|
@@ -761,44 +850,44 @@ def main():
|
|
| 761 |
key=f'doc_str_{idx}')
|
| 762 |
|
| 763 |
# Save and AI operations columns
|
| 764 |
-
col_save, col_ai, col_delete = st.columns(3)
|
| 765 |
-
|
| 766 |
-
with col_save:
|
| 767 |
-
if st.button("💾 Save Changes", key=f'save_runai_{idx}'):
|
| 768 |
-
try:
|
| 769 |
-
updated_doc = json.loads(doc_str)
|
| 770 |
-
# Reinsert ID and name from editable fields
|
| 771 |
-
updated_doc['id'] = editable_id
|
| 772 |
-
updated_doc['name'] = editable_name
|
| 773 |
-
response = container.upsert_item(body=updated_doc)
|
| 774 |
-
if response:
|
| 775 |
-
st.success(f"Document {updated_doc['id']} saved successfully.")
|
| 776 |
-
st.session_state.selected_document_id = updated_doc['id']
|
| 777 |
-
st.rerun()
|
| 778 |
-
except Exception as e:
|
| 779 |
-
st.error(f"Error saving document: {str(e)}")
|
| 780 |
-
|
| 781 |
-
with col_ai:
|
| 782 |
-
if st.button("🤖 Run AI", key=f'run_with_ai_button_{idx}'):
|
| 783 |
-
# Your existing AI processing code here
|
| 784 |
-
values_with_space = []
|
| 785 |
-
def extract_values2(obj):
|
| 786 |
-
if isinstance(obj, dict):
|
| 787 |
-
for k, v in obj.items():
|
| 788 |
-
extract_values2(v)
|
| 789 |
-
elif isinstance(obj, list):
|
| 790 |
-
for item in obj:
|
| 791 |
-
extract_values2(item)
|
| 792 |
-
elif isinstance(obj, str):
|
| 793 |
-
if ' ' in obj:
|
| 794 |
-
values_with_space.append(obj)
|
| 795 |
-
|
| 796 |
-
extract_values2(doc)
|
| 797 |
-
for term in values_with_space:
|
| 798 |
-
display_glossary_entity(term)
|
| 799 |
-
search_glossary(term)
|
| 800 |
|
| 801 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 802 |
elif selected_view == 'Clone Document':
|
| 803 |
st.markdown("#### 📄 Clone Document (Save As)")
|
| 804 |
|
|
|
|
| 684 |
if st.session_state.current_index < total_docs - 1:
|
| 685 |
st.session_state.current_index += 1
|
| 686 |
st.rerun()
|
|
|
|
|
|
|
| 687 |
|
| 688 |
elif selected_view == 'Show as Code Editor':
|
| 689 |
Label = '#### 💻 Code editor view'
|
| 690 |
st.markdown(Label)
|
| 691 |
total_docs = len(documents)
|
| 692 |
+
|
| 693 |
+
if total_docs == 0:
|
| 694 |
+
st.warning("No documents available.")
|
| 695 |
+
return
|
| 696 |
+
|
| 697 |
+
doc = documents[st.session_state.current_index]
|
| 698 |
+
doc_str = st.text_area("Edit Document",
|
| 699 |
+
value=json.dumps(doc, indent=2),
|
| 700 |
+
height=300,
|
| 701 |
+
key=f'code_editor_{st.session_state.current_index}')
|
| 702 |
+
|
| 703 |
+
col_prev, col_next = st.columns([1, 1])
|
| 704 |
+
with col_prev:
|
| 705 |
+
if st.button("⬅️ Previous", key='prev_code'):
|
| 706 |
+
if st.session_state.current_index > 0:
|
| 707 |
+
st.session_state.current_index -= 1
|
| 708 |
+
st.rerun()
|
| 709 |
+
with col_next:
|
| 710 |
+
if st.button("➡️ Next", key='next_code'):
|
| 711 |
+
if st.session_state.current_index < total_docs - 1:
|
| 712 |
+
st.session_state.current_index += 1
|
| 713 |
+
st.rerun()
|
| 714 |
+
|
| 715 |
+
col_save, col_delete = st.columns([1, 1])
|
| 716 |
+
with col_save:
|
| 717 |
+
if st.button("💾 Save Changes", key=f'save_button_{st.session_state.current_index}'):
|
| 718 |
+
try:
|
| 719 |
+
updated_doc = json.loads(doc_str)
|
| 720 |
+
response = container.upsert_item(body=updated_doc)
|
| 721 |
+
if response:
|
| 722 |
+
st.success(f"Document {updated_doc['id']} saved successfully.")
|
| 723 |
+
st.session_state.selected_document_id = updated_doc['id']
|
| 724 |
+
st.rerun()
|
| 725 |
+
except json.JSONDecodeError:
|
| 726 |
+
st.error("Invalid JSON format. Please check your edits.")
|
| 727 |
+
except Exception as e:
|
| 728 |
+
st.error(f"Error saving document: {str(e)}")
|
| 729 |
+
|
| 730 |
+
with col_delete:
|
| 731 |
+
if st.button("🗑️ Delete", key=f'delete_button_{st.session_state.current_index}'):
|
| 732 |
+
try:
|
| 733 |
+
current_doc = json.loads(doc_str)
|
| 734 |
+
doc_id = current_doc.get("id")
|
| 735 |
+
|
| 736 |
+
if not doc_id:
|
| 737 |
+
st.error("Document ID not found.")
|
| 738 |
+
return
|
| 739 |
+
|
| 740 |
+
# Confirm deletion
|
| 741 |
+
if 'confirm_delete' not in st.session_state:
|
| 742 |
+
st.session_state.confirm_delete = False
|
| 743 |
+
|
| 744 |
+
if not st.session_state.confirm_delete:
|
| 745 |
+
if st.button("⚠️ Click to confirm deletion", key=f'confirm_delete_{st.session_state.current_index}'):
|
| 746 |
+
st.session_state.confirm_delete = True
|
| 747 |
+
st.rerun()
|
| 748 |
+
else:
|
| 749 |
+
try:
|
| 750 |
+
# Delete the document
|
| 751 |
+
container.delete_item(item=doc_id, partition_key=doc_id)
|
| 752 |
+
|
| 753 |
+
# Update the session state
|
| 754 |
+
st.session_state.confirm_delete = False
|
| 755 |
+
|
| 756 |
+
# Update the current index if necessary
|
| 757 |
+
if total_docs > 1:
|
| 758 |
+
if st.session_state.current_index == total_docs - 1:
|
| 759 |
+
st.session_state.current_index = max(0, total_docs - 2)
|
| 760 |
+
documents.pop(st.session_state.current_index)
|
| 761 |
+
else:
|
| 762 |
+
st.session_state.current_index = 0
|
| 763 |
+
documents.clear()
|
| 764 |
+
|
| 765 |
+
st.success(f"Document {doc_id} deleted successfully.")
|
| 766 |
+
st.rerun()
|
| 767 |
+
|
| 768 |
+
except Exception as e:
|
| 769 |
+
st.error(f"Error deleting document: {str(e)}")
|
| 770 |
+
st.session_state.confirm_delete = False
|
| 771 |
+
|
| 772 |
+
except json.JSONDecodeError:
|
| 773 |
+
st.error("Invalid JSON format. Please check the document.")
|
| 774 |
+
except Exception as e:
|
| 775 |
+
st.error(f"Error processing deletion: {str(e)}")
|
| 776 |
+
|
| 777 |
+
elif selected_view == 'Show as Code Editor - Old':
|
| 778 |
+
Label = '#### 💻 Code editor view'
|
| 779 |
+
st.markdown(Label)
|
| 780 |
+
total_docs = len(documents)
|
| 781 |
doc = documents[st.session_state.current_index]
|
| 782 |
# st.markdown(f"#### Document ID: {doc.get('id', '')}")
|
| 783 |
doc_str = st.text_area("Edit Document",
|
|
|
|
| 823 |
st.rerun()
|
| 824 |
except Exception as e:
|
| 825 |
st.error(f"Error deleting document: {str(e)}")
|
| 826 |
+
|
| 827 |
+
|
| 828 |
|
| 829 |
|
| 830 |
elif selected_view == 'Show as Run AI':
|
|
|
|
| 850 |
key=f'doc_str_{idx}')
|
| 851 |
|
| 852 |
# Save and AI operations columns
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 853 |
|
| 854 |
+
if st.button("🤖 Run AI", key=f'run_with_ai_button_{idx}'):
|
| 855 |
+
# Your existing AI processing code here
|
| 856 |
+
values_with_space = []
|
| 857 |
+
def extract_values2(obj):
|
| 858 |
+
if isinstance(obj, dict):
|
| 859 |
+
for k, v in obj.items():
|
| 860 |
+
extract_values2(v)
|
| 861 |
+
elif isinstance(obj, list):
|
| 862 |
+
for item in obj:
|
| 863 |
+
extract_values2(item)
|
| 864 |
+
elif isinstance(obj, str):
|
| 865 |
+
if ' ' in obj:
|
| 866 |
+
values_with_space.append(obj)
|
| 867 |
+
|
| 868 |
+
extract_values2(doc)
|
| 869 |
+
for term in values_with_space:
|
| 870 |
+
display_glossary_entity(term)
|
| 871 |
+
search_glossary(term)
|
| 872 |
+
|
| 873 |
+
if st.button("💾 Save Changes", key=f'save_runai_{idx}'):
|
| 874 |
+
try:
|
| 875 |
+
updated_doc = json.loads(doc_str)
|
| 876 |
+
# Reinsert ID and name from editable fields
|
| 877 |
+
updated_doc['id'] = editable_id
|
| 878 |
+
updated_doc['name'] = editable_name
|
| 879 |
+
response = container.upsert_item(body=updated_doc)
|
| 880 |
+
if response:
|
| 881 |
+
st.success(f"Document {updated_doc['id']} saved successfully.")
|
| 882 |
+
st.session_state.selected_document_id = updated_doc['id']
|
| 883 |
+
st.rerun()
|
| 884 |
+
except Exception as e:
|
| 885 |
+
st.error(f"Error saving document: {str(e)}")
|
| 886 |
+
|
| 887 |
+
|
| 888 |
+
|
| 889 |
+
|
| 890 |
+
|
| 891 |
elif selected_view == 'Clone Document':
|
| 892 |
st.markdown("#### 📄 Clone Document (Save As)")
|
| 893 |
|