MarcosRodrigo commited on
Commit
6f6afc3
·
verified ·
1 Parent(s): 450aeed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -30,9 +30,17 @@ def load_current_selections():
30
  else:
31
  return pd.DataFrame(columns=["Name", "Drinks", "Food"])
32
 
33
- # Save current user selections to the shared CSV file
34
  def save_current_selection_to_file(current_selections):
35
- current_selections.to_csv(TEMP_FILE, index=False)
 
 
 
 
 
 
 
 
36
 
37
  # Upload the shared file to Hugging Face repository for persistence
38
  def upload_temp_file_to_repo():
@@ -138,13 +146,13 @@ if menu == "Poll":
138
  st.session_state.history.append({"Date": timestamp, "Summary": df})
139
  st.success(f"Summary submitted at {timestamp}")
140
  st.session_state.step = 1
141
- # Use st.experimental_set_query_params() to force a refresh
142
  st.experimental_set_query_params(step="reset")
143
 
144
  # "Current" view to display the current summary of all users' selections
145
  elif menu == "Current":
146
  st.title("Current Selections of All Users")
147
- download_temp_file_from_repo()
 
148
  current_df = load_current_selections()
149
  st.table(current_df)
150
 
 
30
  else:
31
  return pd.DataFrame(columns=["Name", "Drinks", "Food"])
32
 
33
+ # Save current user selections to the shared CSV file without overwriting previous data
34
  def save_current_selection_to_file(current_selections):
35
+ # Read the existing file to avoid overwriting
36
+ if os.path.exists(TEMP_FILE):
37
+ existing_selections = pd.read_csv(TEMP_FILE)
38
+ combined_selections = pd.concat([existing_selections, current_selections]).drop_duplicates()
39
+ else:
40
+ combined_selections = current_selections
41
+
42
+ # Save the updated DataFrame to the CSV file
43
+ combined_selections.to_csv(TEMP_FILE, index=False)
44
 
45
  # Upload the shared file to Hugging Face repository for persistence
46
  def upload_temp_file_to_repo():
 
146
  st.session_state.history.append({"Date": timestamp, "Summary": df})
147
  st.success(f"Summary submitted at {timestamp}")
148
  st.session_state.step = 1
 
149
  st.experimental_set_query_params(step="reset")
150
 
151
  # "Current" view to display the current summary of all users' selections
152
  elif menu == "Current":
153
  st.title("Current Selections of All Users")
154
+ if st.button("Reload Selections"):
155
+ download_temp_file_from_repo() # Download the latest version of the shared file
156
  current_df = load_current_selections()
157
  st.table(current_df)
158