abubasith86 commited on
Commit
b69fe64
Β·
verified Β·
1 Parent(s): ec772c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -7
app.py CHANGED
@@ -74,6 +74,11 @@ column_configs = {
74
  }
75
 
76
  # --- Use st.data_editor for editable table ---
 
 
 
 
 
77
  edited_df = st.data_editor(
78
  df,
79
  use_container_width=True,
@@ -81,16 +86,20 @@ edited_df = st.data_editor(
81
  column_config=column_configs,
82
  )
83
 
84
- # --- Save updated data ---
85
  if edited_df is not None:
86
- st.session_state.data = edited_df.fillna("").to_dict(orient="records")
87
 
88
- # Save to temp file
89
- with open(TMP_FILE, "w", encoding="utf-8") as f:
90
- for item in st.session_state.data:
91
- f.write(json.dumps(item, ensure_ascii=False) + "\n")
 
 
 
 
 
92
 
93
- st.toast("βœ… Changes auto-saved!", icon="πŸ’Ύ")
94
 
95
  # --- Add New Entry ---
96
  st.markdown("### βž• Add New Entry")
 
74
  }
75
 
76
  # --- Use st.data_editor for editable table ---
77
+ # Track previous data
78
+ if "prev_data" not in st.session_state:
79
+ st.session_state.prev_data = []
80
+
81
+ # Show editable table
82
  edited_df = st.data_editor(
83
  df,
84
  use_container_width=True,
 
86
  column_config=column_configs,
87
  )
88
 
89
+ # Save only if data has changed
90
  if edited_df is not None:
91
+ new_data = edited_df.fillna("").to_dict(orient="records")
92
 
93
+ if new_data != st.session_state.prev_data:
94
+ st.session_state.data = new_data
95
+ st.session_state.prev_data = new_data
96
+
97
+ with open(TMP_FILE, "w", encoding="utf-8") as f:
98
+ for item in new_data:
99
+ f.write(json.dumps(item, ensure_ascii=False) + "\n")
100
+
101
+ st.toast("βœ… Auto-saved changes!", icon="πŸ’Ύ")
102
 
 
103
 
104
  # --- Add New Entry ---
105
  st.markdown("### βž• Add New Entry")