MarcosRodrigo commited on
Commit
1944cec
·
verified ·
1 Parent(s): 36c1ffd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -31
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
- if 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,45 +135,46 @@ if menu == "Poll":
135
  "Italiano", "Café con soja", "Té", "Manzanilla", "Nada"
136
  ]
137
 
138
- # Display the dropdown if `show_drinks_dropdown` is True
139
- if st.session_state.get("show_drinks_dropdown", True):
140
- st.session_state.selected_drinks = st.multiselect("Choose your drinks:", drinks_options)
141
 
142
- if st.session_state.get("show_drinks_dropdown", True) and st.session_state.selected_drinks:
143
- # If drinks are selected, hide the dropdown and show confirmation text
144
- st.session_state.show_drinks_dropdown = False
 
145
 
146
- if st.button("Next", key="step2_next") and not st.session_state.get("show_drinks_dropdown", True):
147
- # Use the session state to access the selected drinks
148
- st.session_state.current_selections.append({"Name": st.session_state.users[-1], "Drinks": st.session_state.selected_drinks})
149
- st.session_state.show_food_dropdown = True # Initialize the dropdown state for Step 3
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
- if st.session_state.step == 3:
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
- # Display the dropdown if `show_food_dropdown` is True
162
- if st.session_state.get("show_food_dropdown", True):
163
- st.session_state.selected_food = st.multiselect("Choose your food:", food_options)
164
-
165
- if st.session_state.get("show_food_dropdown", True) and st.session_state.selected_food:
166
- # If food is selected, hide the dropdown and show confirmation text
167
- st.session_state.show_food_dropdown = False
168
-
169
- if st.button("Save Selections", key="save_selections") and not st.session_state.get("show_food_dropdown", True):
170
- # Use the session state to access the selected food
171
- st.session_state.current_selections[-1]["Food"] = st.session_state.selected_food
172
- df = pd.DataFrame(st.session_state.current_selections)
173
- save_current_selection_to_file(df)
174
- upload_temp_file_to_repo()
175
- st.success(f"Selections saved for {st.session_state.users[-1]}!")
176
- st.session_state.step = 1
 
 
 
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":