Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from datetime import datetime
|
| 4 |
+
|
| 5 |
+
# Initialize session state for temporary and historical storage
|
| 6 |
+
if "users" not in st.session_state:
|
| 7 |
+
st.session_state.users = []
|
| 8 |
+
if "current_selections" not in st.session_state:
|
| 9 |
+
st.session_state.current_selections = []
|
| 10 |
+
if "history" not in st.session_state:
|
| 11 |
+
st.session_state.history = []
|
| 12 |
+
|
| 13 |
+
# Sidebar for navigating through different views
|
| 14 |
+
menu = st.sidebar.selectbox("Select View", ["Poll", "History"])
|
| 15 |
+
|
| 16 |
+
# Function to reset the current selections after submission
|
| 17 |
+
def reset_selections():
|
| 18 |
+
st.session_state.users = []
|
| 19 |
+
st.session_state.current_selections = []
|
| 20 |
+
|
| 21 |
+
# Poll view with four consecutive steps
|
| 22 |
+
if menu == "Poll":
|
| 23 |
+
st.title("Breakfast Poll Application")
|
| 24 |
+
|
| 25 |
+
# Step 1: User's Name
|
| 26 |
+
if "step" not in st.session_state:
|
| 27 |
+
st.session_state.step = 1
|
| 28 |
+
|
| 29 |
+
if st.session_state.step == 1:
|
| 30 |
+
st.header("Step 1: Enter your name")
|
| 31 |
+
name = st.text_input("Name:")
|
| 32 |
+
if st.button("Next") and name:
|
| 33 |
+
st.session_state.users.append(name)
|
| 34 |
+
st.session_state.step = 2
|
| 35 |
+
|
| 36 |
+
# Step 2: Select Drinks
|
| 37 |
+
if st.session_state.step == 2:
|
| 38 |
+
st.header("Step 2: Select your drink(s)")
|
| 39 |
+
drinks_options = [
|
| 40 |
+
"Café con leche", "Colacao", "Descafeinado con leche", "Cortado",
|
| 41 |
+
"Aguasusia", "Aguasusia susia", "Café descafeinado con leche desnatada",
|
| 42 |
+
"Italiano", "Café con soja", "Té", "Manzanilla", "Nada"
|
| 43 |
+
]
|
| 44 |
+
selected_drinks = st.multiselect("Choose your drinks:", drinks_options)
|
| 45 |
+
if st.button("Next") and selected_drinks:
|
| 46 |
+
st.session_state.current_selections.append({"Name": st.session_state.users[-1], "Drinks": selected_drinks})
|
| 47 |
+
st.session_state.step = 3
|
| 48 |
+
|
| 49 |
+
# Step 3: Select Food
|
| 50 |
+
if st.session_state.step == 3:
|
| 51 |
+
st.header("Step 3: Select your food(s)")
|
| 52 |
+
food_options = [
|
| 53 |
+
"Barrita con aceite", "Barrita con tomate", "Palmera de chocolate",
|
| 54 |
+
"Palmera de chocolate blanco", "Yogurt", "Pincho de tortilla", "Nada"
|
| 55 |
+
]
|
| 56 |
+
selected_food = st.multiselect("Choose your food:", food_options)
|
| 57 |
+
if st.button("Next") and selected_food:
|
| 58 |
+
st.session_state.current_selections[-1]["Food"] = selected_food
|
| 59 |
+
st.session_state.step = 4
|
| 60 |
+
|
| 61 |
+
# Step 4: Display Summary
|
| 62 |
+
if st.session_state.step == 4:
|
| 63 |
+
st.header("Step 4: Summary of Selections")
|
| 64 |
+
if st.session_state.current_selections:
|
| 65 |
+
df = pd.DataFrame(st.session_state.current_selections)
|
| 66 |
+
st.table(df)
|
| 67 |
+
|
| 68 |
+
if st.button("Submit Summary"):
|
| 69 |
+
# Save the current summary to history with a timestamp
|
| 70 |
+
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 71 |
+
st.session_state.history.append({"Date": timestamp, "Summary": df})
|
| 72 |
+
st.success(f"Summary submitted at {timestamp}")
|
| 73 |
+
reset_selections()
|
| 74 |
+
st.session_state.step = 1
|
| 75 |
+
|
| 76 |
+
# History view to check past summaries
|
| 77 |
+
elif menu == "History":
|
| 78 |
+
st.title("Breakfast Poll History")
|
| 79 |
+
if st.session_state.history:
|
| 80 |
+
for record in st.session_state.history:
|
| 81 |
+
st.subheader(f"Date: {record['Date']}")
|
| 82 |
+
st.table(record["Summary"])
|
| 83 |
+
else:
|
| 84 |
+
st.write("No history records found.")
|