Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -32,6 +32,10 @@ def load_current_selections():
|
|
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)
|
@@ -77,12 +81,9 @@ def load_history():
|
|
77 |
def save_summary_to_history():
|
78 |
timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
|
79 |
history_filename = f"{HISTORY_DIR}/{timestamp}.txt"
|
80 |
-
# Read the current selections file
|
81 |
if os.path.exists(TEMP_FILE):
|
82 |
summary_df = pd.read_csv(TEMP_FILE)
|
83 |
-
# Save the DataFrame to a text file in the history directory
|
84 |
summary_df.to_csv(history_filename, index=False)
|
85 |
-
# Upload the file to the repository
|
86 |
upload_file(path_or_fileobj=history_filename, path_in_repo=history_filename, repo_id=REPO_ID, token=hf_token, repo_type="space")
|
87 |
return timestamp
|
88 |
|
@@ -144,15 +145,14 @@ if menu == "Poll":
|
|
144 |
elif menu == "Current":
|
145 |
st.title("Current Selections of All Users")
|
146 |
if st.button("Reload Selections"):
|
147 |
-
download_temp_file_from_repo()
|
148 |
current_df = load_current_selections()
|
149 |
st.table(current_df)
|
150 |
if st.button("Submit Summary to History"):
|
151 |
timestamp = save_summary_to_history()
|
152 |
st.success(f"Summary saved to history at {timestamp}")
|
153 |
-
# Clear the current selections
|
154 |
os.remove(TEMP_FILE)
|
155 |
-
upload_temp_file_to_repo()
|
156 |
st.experimental_set_query_params(step="reset")
|
157 |
|
158 |
# History view to check past summaries
|
|
|
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 |
+
# Convert list columns to strings to avoid unhashable type errors
|
36 |
+
current_selections["Drinks"] = current_selections["Drinks"].apply(lambda x: ", ".join(x) if isinstance(x, list) else x)
|
37 |
+
current_selections["Food"] = current_selections["Food"].apply(lambda x: ", ".join(x) if isinstance(x, list) else x)
|
38 |
+
|
39 |
# Read the existing file to avoid overwriting
|
40 |
if os.path.exists(TEMP_FILE):
|
41 |
existing_selections = pd.read_csv(TEMP_FILE)
|
|
|
81 |
def save_summary_to_history():
|
82 |
timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
|
83 |
history_filename = f"{HISTORY_DIR}/{timestamp}.txt"
|
|
|
84 |
if os.path.exists(TEMP_FILE):
|
85 |
summary_df = pd.read_csv(TEMP_FILE)
|
|
|
86 |
summary_df.to_csv(history_filename, index=False)
|
|
|
87 |
upload_file(path_or_fileobj=history_filename, path_in_repo=history_filename, repo_id=REPO_ID, token=hf_token, repo_type="space")
|
88 |
return timestamp
|
89 |
|
|
|
145 |
elif menu == "Current":
|
146 |
st.title("Current Selections of All Users")
|
147 |
if st.button("Reload Selections"):
|
148 |
+
download_temp_file_from_repo()
|
149 |
current_df = load_current_selections()
|
150 |
st.table(current_df)
|
151 |
if st.button("Submit Summary to History"):
|
152 |
timestamp = save_summary_to_history()
|
153 |
st.success(f"Summary saved to history at {timestamp}")
|
|
|
154 |
os.remove(TEMP_FILE)
|
155 |
+
upload_temp_file_to_repo()
|
156 |
st.experimental_set_query_params(step="reset")
|
157 |
|
158 |
# History view to check past summaries
|