Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -735,78 +735,19 @@ def main():
|
|
| 735 |
if st.session_state.current_index < total_docs - 1:
|
| 736 |
st.session_state.current_index += 1
|
| 737 |
st.rerun()
|
| 738 |
-
|
| 739 |
-
elif selected_view == 'Show as Code Editor':
|
| 740 |
-
Label = '# 💻 Code editor view - Code is poetry, bugs are typos'
|
| 741 |
-
st.markdown(Label)
|
| 742 |
-
total_docs = len(documents)
|
| 743 |
-
doc = documents[st.session_state.current_index]
|
| 744 |
-
st.markdown(f"#### Document ID: {doc.get('id', '')}")
|
| 745 |
-
doc_str = st.text_area("Edit Document",
|
| 746 |
-
value=json.dumps(doc, indent=2),
|
| 747 |
-
height=300,
|
| 748 |
-
key=f'code_editor_{st.session_state.current_index}')
|
| 749 |
-
|
| 750 |
-
# ⬅️➡️ Navigation controls
|
| 751 |
-
col_prev, col_next = st.columns([1, 1])
|
| 752 |
-
with col_prev:
|
| 753 |
-
if st.button("⬅️ Previous", key='prev_code'):
|
| 754 |
-
if st.session_state.current_index > 0:
|
| 755 |
-
st.session_state.current_index -= 1
|
| 756 |
-
st.rerun()
|
| 757 |
-
with col_next:
|
| 758 |
-
if st.button("➡️ Next", key='next_code'):
|
| 759 |
-
if st.session_state.current_index < total_docs - 1:
|
| 760 |
-
st.session_state.current_index += 1
|
| 761 |
-
st.rerun()
|
| 762 |
-
|
| 763 |
-
# 💾 🗑️ Save and Delete controls
|
| 764 |
-
col_save, col_delete = st.columns([1, 1])
|
| 765 |
-
with col_save:
|
| 766 |
-
if st.button("💾 Save Changes", key=f'save_button_{st.session_state.current_index}'):
|
| 767 |
-
try:
|
| 768 |
-
updated_doc = json.loads(doc_str)
|
| 769 |
-
success, message = update_record(container, updated_doc)
|
| 770 |
-
if success:
|
| 771 |
-
st.success(f"Document {updated_doc['id']} saved successfully.")
|
| 772 |
-
st.session_state.selected_document_id = updated_doc['id']
|
| 773 |
-
st.rerun()
|
| 774 |
-
else:
|
| 775 |
-
st.error(message)
|
| 776 |
-
except json.JSONDecodeError as e:
|
| 777 |
-
st.error(f"Invalid JSON: {str(e)} 🚫")
|
| 778 |
|
| 779 |
-
|
| 780 |
-
if st.button("🗑️ Delete", key=f'delete_button_{st.session_state.current_index}'):
|
| 781 |
-
try:
|
| 782 |
-
current_doc = json.loads(doc_str)
|
| 783 |
-
response = container.delete_item(
|
| 784 |
-
item=current_doc['id'],
|
| 785 |
-
partition_key=current_doc['id']
|
| 786 |
-
)
|
| 787 |
-
if response:
|
| 788 |
-
st.success(f"Document {current_doc['id']} deleted successfully.")
|
| 789 |
-
if st.session_state.current_index > 0:
|
| 790 |
-
st.session_state.current_index -= 1
|
| 791 |
-
st.rerun()
|
| 792 |
-
except Exception as e:
|
| 793 |
-
st.error(f"Error deleting document: {str(e)}")
|
| 794 |
-
|
| 795 |
-
|
| 796 |
-
elif selected_view == 'Show as Code Editor2':
|
| 797 |
Label = '# 💻 Code editor view - Code is poetry, bugs are typos'
|
| 798 |
st.markdown(Label)
|
| 799 |
total_docs = len(documents)
|
| 800 |
doc = documents[st.session_state.current_index]
|
| 801 |
st.markdown(f"#### Document ID: {doc.get('id', '')}")
|
| 802 |
doc_str = st.text_area("Edit Document",
|
| 803 |
-
|
| 804 |
-
|
| 805 |
-
|
| 806 |
-
|
| 807 |
-
|
| 808 |
|
| 809 |
-
# ⬅️➡️ Navigation
|
| 810 |
col_prev, col_next = st.columns([1, 1])
|
| 811 |
with col_prev:
|
| 812 |
if st.button("⬅️ Previous", key='prev_code'):
|
|
@@ -818,23 +759,39 @@ def main():
|
|
| 818 |
if st.session_state.current_index < total_docs - 1:
|
| 819 |
st.session_state.current_index += 1
|
| 820 |
st.rerun()
|
| 821 |
-
|
| 822 |
-
|
| 823 |
|
| 824 |
-
# 💾
|
| 825 |
-
|
| 826 |
-
|
| 827 |
-
|
| 828 |
-
|
| 829 |
-
|
| 830 |
-
|
| 831 |
-
|
| 832 |
-
|
| 833 |
-
|
| 834 |
-
|
| 835 |
-
|
| 836 |
-
|
| 837 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 838 |
|
| 839 |
|
| 840 |
|
|
|
|
| 735 |
if st.session_state.current_index < total_docs - 1:
|
| 736 |
st.session_state.current_index += 1
|
| 737 |
st.rerun()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 738 |
|
| 739 |
+
elif selected_view == 'Show as Code Editor':
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 740 |
Label = '# 💻 Code editor view - Code is poetry, bugs are typos'
|
| 741 |
st.markdown(Label)
|
| 742 |
total_docs = len(documents)
|
| 743 |
doc = documents[st.session_state.current_index]
|
| 744 |
st.markdown(f"#### Document ID: {doc.get('id', '')}")
|
| 745 |
doc_str = st.text_area("Edit Document",
|
| 746 |
+
value=json.dumps(doc, indent=2),
|
| 747 |
+
height=300,
|
| 748 |
+
key=f'code_editor_{st.session_state.current_index}')
|
|
|
|
|
|
|
| 749 |
|
| 750 |
+
# ⬅️➡️ Navigation controls
|
| 751 |
col_prev, col_next = st.columns([1, 1])
|
| 752 |
with col_prev:
|
| 753 |
if st.button("⬅️ Previous", key='prev_code'):
|
|
|
|
| 759 |
if st.session_state.current_index < total_docs - 1:
|
| 760 |
st.session_state.current_index += 1
|
| 761 |
st.rerun()
|
|
|
|
|
|
|
| 762 |
|
| 763 |
+
# 💾 🗑️ Save and Delete controls
|
| 764 |
+
col_save, col_delete = st.columns([1, 1])
|
| 765 |
+
with col_save:
|
| 766 |
+
if st.button("💾 Save Changes", key=f'save_button_{st.session_state.current_index}'):
|
| 767 |
+
try:
|
| 768 |
+
updated_doc = json.loads(doc_str)
|
| 769 |
+
success, message = update_record(container, updated_doc)
|
| 770 |
+
if success:
|
| 771 |
+
st.success(f"Document {updated_doc['id']} saved successfully.")
|
| 772 |
+
st.session_state.selected_document_id = updated_doc['id']
|
| 773 |
+
st.rerun()
|
| 774 |
+
else:
|
| 775 |
+
st.error(message)
|
| 776 |
+
except json.JSONDecodeError as e:
|
| 777 |
+
st.error(f"Invalid JSON: {str(e)} 🚫")
|
| 778 |
+
|
| 779 |
+
with col_delete:
|
| 780 |
+
if st.button("🗑️ Delete", key=f'delete_button_{st.session_state.current_index}'):
|
| 781 |
+
try:
|
| 782 |
+
current_doc = json.loads(doc_str)
|
| 783 |
+
response = container.delete_item(
|
| 784 |
+
item=current_doc['id'],
|
| 785 |
+
partition_key=current_doc['id']
|
| 786 |
+
)
|
| 787 |
+
if response:
|
| 788 |
+
st.success(f"Document {current_doc['id']} deleted successfully.")
|
| 789 |
+
if st.session_state.current_index > 0:
|
| 790 |
+
st.session_state.current_index -= 1
|
| 791 |
+
st.rerun()
|
| 792 |
+
except Exception as e:
|
| 793 |
+
st.error(f"Error deleting document: {str(e)}")
|
| 794 |
+
|
| 795 |
|
| 796 |
|
| 797 |
|