Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -712,6 +712,7 @@ def main():
|
|
| 712 |
st.session_state.current_index += 1
|
| 713 |
st.rerun()
|
| 714 |
|
|
|
|
| 715 |
elif selected_view == 'Show as Code Editor':
|
| 716 |
Label = '# 💻 Code editor view'
|
| 717 |
st.markdown(Label)
|
|
@@ -735,6 +736,59 @@ def main():
|
|
| 735 |
st.session_state.current_index += 1
|
| 736 |
st.rerun()
|
| 737 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 738 |
col_save, col_delete = st.columns([1, 1])
|
| 739 |
with col_save:
|
| 740 |
if st.button("💾 Save Changes", key=f'save_button_{st.session_state.current_index}'):
|
|
|
|
| 712 |
st.session_state.current_index += 1
|
| 713 |
st.rerun()
|
| 714 |
|
| 715 |
+
|
| 716 |
elif selected_view == 'Show as Code Editor':
|
| 717 |
Label = '# 💻 Code editor view'
|
| 718 |
st.markdown(Label)
|
|
|
|
| 736 |
st.session_state.current_index += 1
|
| 737 |
st.rerun()
|
| 738 |
|
| 739 |
+
col_save, col_delete = st.columns([1, 1])
|
| 740 |
+
with col_save:
|
| 741 |
+
if st.button("💾 Save Changes", key=f'save_button_{st.session_state.current_index}'):
|
| 742 |
+
try:
|
| 743 |
+
updated_doc = json.loads(doc_str)
|
| 744 |
+
response = container.upsert_item(body=updated_doc)
|
| 745 |
+
if response:
|
| 746 |
+
st.success(f"Document {updated_doc['id']} saved successfully.")
|
| 747 |
+
st.session_state.selected_document_id = updated_doc['id']
|
| 748 |
+
st.rerun()
|
| 749 |
+
except Exception as e:
|
| 750 |
+
st.error(f"Error saving document: {str(e)}")
|
| 751 |
+
|
| 752 |
+
with col_delete:
|
| 753 |
+
if st.button("🗑️ Delete", key=f'delete_button_{st.session_state.current_index}'):
|
| 754 |
+
try:
|
| 755 |
+
current_doc = json.loads(doc_str)
|
| 756 |
+
doc_id = current_doc['id']
|
| 757 |
+
response = container.delete_item(item=doc_id, partition_key=doc_id)
|
| 758 |
+
if response:
|
| 759 |
+
st.success(f"Document {doc_id} deleted successfully.")
|
| 760 |
+
if st.session_state.current_index > 0:
|
| 761 |
+
st.session_state.current_index -= 1
|
| 762 |
+
st.rerun()
|
| 763 |
+
except Exception as e:
|
| 764 |
+
st.error(f"Error deleting document: {str(e)}")
|
| 765 |
+
|
| 766 |
+
|
| 767 |
+
|
| 768 |
+
|
| 769 |
+
elif selected_view == 'Show as Code Editor 3':
|
| 770 |
+
Label = '# 💻 Code editor view'
|
| 771 |
+
st.markdown(Label)
|
| 772 |
+
total_docs = len(documents)
|
| 773 |
+
doc = documents[st.session_state.current_index]
|
| 774 |
+
st.markdown(f"#### Document ID: {doc.get('id', '')}")
|
| 775 |
+
doc_str = st.text_area("Edit Document",
|
| 776 |
+
value=json.dumps(doc, indent=2),
|
| 777 |
+
height=300,
|
| 778 |
+
key=f'code_editor_{st.session_state.current_index}')
|
| 779 |
+
|
| 780 |
+
col_prev, col_next = st.columns([1, 1])
|
| 781 |
+
with col_prev:
|
| 782 |
+
if st.button("⬅️ Previous", key='prev_code'):
|
| 783 |
+
if st.session_state.current_index > 0:
|
| 784 |
+
st.session_state.current_index -= 1
|
| 785 |
+
st.rerun()
|
| 786 |
+
with col_next:
|
| 787 |
+
if st.button("➡️ Next", key='next_code'):
|
| 788 |
+
if st.session_state.current_index < total_docs - 1:
|
| 789 |
+
st.session_state.current_index += 1
|
| 790 |
+
st.rerun()
|
| 791 |
+
|
| 792 |
col_save, col_delete = st.columns([1, 1])
|
| 793 |
with col_save:
|
| 794 |
if st.button("💾 Save Changes", key=f'save_button_{st.session_state.current_index}'):
|