Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -122,12 +122,12 @@ if menu == "Poll":
|
|
| 122 |
name = st.text_input("Name:")
|
| 123 |
if st.button("Next", key="step1_next") and name:
|
| 124 |
st.session_state.users.append(name)
|
| 125 |
-
st.session_state.show_drinks_dropdown = True # Initialize the dropdown state for Step 2
|
| 126 |
st.session_state.selected_drinks = [] # Initialize an empty list to store selected drinks
|
|
|
|
| 127 |
st.session_state.step = 2
|
| 128 |
|
| 129 |
# Step 2: Select Drinks
|
| 130 |
-
|
| 131 |
st.header("Step 2: Select your drink(s)")
|
| 132 |
drinks_options = [
|
| 133 |
"Café con leche", "Colacao", "Descafeinado con leche", "Cortado",
|
|
@@ -135,45 +135,46 @@ if menu == "Poll":
|
|
| 135 |
"Italiano", "Café con soja", "Té", "Manzanilla", "Nada"
|
| 136 |
]
|
| 137 |
|
| 138 |
-
#
|
| 139 |
-
|
| 140 |
-
st.session_state.selected_drinks = st.multiselect("Choose your drinks:", drinks_options)
|
| 141 |
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
st.session_state.
|
|
|
|
| 145 |
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
st.
|
| 149 |
-
|
| 150 |
-
st.session_state.selected_food = [] # Initialize an empty list to store selected food
|
| 151 |
-
st.session_state.step = 3
|
| 152 |
|
| 153 |
# Step 3: Select Food
|
| 154 |
-
|
| 155 |
st.header("Step 3: Select your food(s)")
|
| 156 |
food_options = [
|
| 157 |
"Barrita con aceite", "Barrita con tomate", "Palmera de chocolate",
|
| 158 |
"Palmera de chocolate blanco", "Yogurt", "Pincho de tortilla", "Nada"
|
| 159 |
]
|
| 160 |
|
| 161 |
-
#
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
if
|
| 166 |
-
|
| 167 |
-
st.
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
st.
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
|
|
|
|
|
|
|
|
|
| 177 |
|
| 178 |
# "Current" view to display the current summary of all users' selections and submit to history
|
| 179 |
elif menu == "Current":
|
|
|
|
| 122 |
name = st.text_input("Name:")
|
| 123 |
if st.button("Next", key="step1_next") and name:
|
| 124 |
st.session_state.users.append(name)
|
|
|
|
| 125 |
st.session_state.selected_drinks = [] # Initialize an empty list to store selected drinks
|
| 126 |
+
st.session_state.selected_food = [] # Initialize an empty list to store selected food
|
| 127 |
st.session_state.step = 2
|
| 128 |
|
| 129 |
# Step 2: Select Drinks
|
| 130 |
+
elif st.session_state.step == 2:
|
| 131 |
st.header("Step 2: Select your drink(s)")
|
| 132 |
drinks_options = [
|
| 133 |
"Café con leche", "Colacao", "Descafeinado con leche", "Cortado",
|
|
|
|
| 135 |
"Italiano", "Café con soja", "Té", "Manzanilla", "Nada"
|
| 136 |
]
|
| 137 |
|
| 138 |
+
# Use st.multiselect to select drinks
|
| 139 |
+
selected_drinks = st.multiselect("Choose your drinks:", drinks_options, key="drinks_multiselect")
|
|
|
|
| 140 |
|
| 141 |
+
# Collapse the dropdown after selection by storing the value in session state
|
| 142 |
+
if selected_drinks:
|
| 143 |
+
st.session_state.selected_drinks = selected_drinks
|
| 144 |
+
st.experimental_rerun() # Force a rerun to collapse the dropdown
|
| 145 |
|
| 146 |
+
# Show the "Next" button only if there are selected drinks
|
| 147 |
+
if st.session_state.selected_drinks:
|
| 148 |
+
if st.button("Next", key="step2_next"):
|
| 149 |
+
st.session_state.step = 3
|
|
|
|
|
|
|
| 150 |
|
| 151 |
# Step 3: Select Food
|
| 152 |
+
elif st.session_state.step == 3:
|
| 153 |
st.header("Step 3: Select your food(s)")
|
| 154 |
food_options = [
|
| 155 |
"Barrita con aceite", "Barrita con tomate", "Palmera de chocolate",
|
| 156 |
"Palmera de chocolate blanco", "Yogurt", "Pincho de tortilla", "Nada"
|
| 157 |
]
|
| 158 |
|
| 159 |
+
# Use st.multiselect to select food
|
| 160 |
+
selected_food = st.multiselect("Choose your food:", food_options, key="food_multiselect")
|
| 161 |
+
|
| 162 |
+
# Collapse the dropdown after selection by storing the value in session state
|
| 163 |
+
if selected_food:
|
| 164 |
+
st.session_state.selected_food = selected_food
|
| 165 |
+
st.experimental_rerun() # Force a rerun to collapse the dropdown
|
| 166 |
+
|
| 167 |
+
# Show the "Save Selections" button only if there is selected food
|
| 168 |
+
if st.session_state.selected_food:
|
| 169 |
+
if st.button("Save Selections", key="save_selections"):
|
| 170 |
+
st.session_state.current_selections[-1]["Food"] = st.session_state.selected_food
|
| 171 |
+
df = pd.DataFrame(st.session_state.current_selections)
|
| 172 |
+
save_current_selection_to_file(df)
|
| 173 |
+
upload_temp_file_to_repo()
|
| 174 |
+
st.success(f"Selections saved for {st.session_state.users[-1]}!")
|
| 175 |
+
st.session_state.step = 1 # Reset to step 1 for the next user
|
| 176 |
+
st.session_state.selected_drinks = [] # Reset the drinks selection
|
| 177 |
+
st.session_state.selected_food = [] # Reset the food selection
|
| 178 |
|
| 179 |
# "Current" view to display the current summary of all users' selections and submit to history
|
| 180 |
elif menu == "Current":
|