Spaces:
Configuration error
Configuration error
Basic functionality in place.
Browse files- pages/dish_planning.py +54 -25
- pages/user_0_event_participation.py +9 -0
- pages/user_3_profile.py +1 -0
- utils/allergy_input.py +37 -30
- utils/event_participation.py +23 -0
pages/dish_planning.py
CHANGED
|
@@ -6,35 +6,64 @@ from utils.variables import *
|
|
| 6 |
st.title("Dish planning")
|
| 7 |
st.write("Welcome to the dish planning page!")
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
found = True
|
| 30 |
break
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
|
|
|
| 38 |
|
| 39 |
|
| 40 |
# Text input for the search query
|
|
|
|
| 6 |
st.title("Dish planning")
|
| 7 |
st.write("Welcome to the dish planning page!")
|
| 8 |
|
| 9 |
+
|
| 10 |
+
#for u in user_list.keys():
|
| 11 |
+
# for i in user_list[u].keys():
|
| 12 |
+
# st.write(f"user id: {u}, i: {i}")
|
| 13 |
+
# for i in user_list[u][i]:
|
| 14 |
+
# st.write(i)
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
col1, col2 = st.columns(2)
|
| 18 |
+
with col1:
|
| 19 |
+
st.header("Ingredients:")
|
| 20 |
+
for i in ingredient_list:
|
| 21 |
+
allergic_people_count = 0
|
| 22 |
+
for u in user_list.values():
|
| 23 |
+
if i in u.keys():
|
| 24 |
+
allergic_people_count += 1
|
| 25 |
+
else:
|
| 26 |
+
found = False
|
| 27 |
+
for s in synonyms[i]:
|
| 28 |
+
if found:
|
|
|
|
| 29 |
break
|
| 30 |
+
else:
|
| 31 |
+
if s in u.keys():
|
| 32 |
+
allergic_people_count += 1
|
| 33 |
+
found = True
|
| 34 |
+
break
|
| 35 |
|
| 36 |
+
if allergic_people_count > 0:
|
| 37 |
+
st.write(f"{i} - {allergic_people_count} are sensitive to this ingredient")
|
| 38 |
+
else:
|
| 39 |
+
st.write(f"{i}")
|
| 40 |
+
|
| 41 |
+
with col2:
|
| 42 |
+
st.header("Aggregate:")
|
| 43 |
+
user_pools = defaultdict(lambda: False)
|
| 44 |
+
|
| 45 |
+
# Summary of allergies
|
| 46 |
+
for user_id in user_list.keys():
|
| 47 |
+
relevant_allergy_list = ""
|
| 48 |
+
for ingredient in ingredient_list:
|
| 49 |
+
if ingredient in user_list[user_id].keys():
|
| 50 |
+
if relevant_allergy_list == "":
|
| 51 |
+
relevant_allergy_list = relevant_allergy_list + ingredient
|
| 52 |
+
else:
|
| 53 |
+
relevant_allergy_list = relevant_allergy_list + ", " + ingredient
|
| 54 |
+
if not relevant_allergy_list == "":
|
| 55 |
+
if not user_pools[relevant_allergy_list]:
|
| 56 |
+
user_pools[relevant_allergy_list] = 1
|
| 57 |
+
else:
|
| 58 |
+
user_pools[relevant_allergy_list] += 1
|
| 59 |
|
| 60 |
+
total_affected_guests = 0
|
| 61 |
+
for pool in user_pools.keys():
|
| 62 |
+
#relevant_allergies = pool.split(",")
|
| 63 |
+
st.write(f"{user_pools[pool]} users cannot eat {pool}")
|
| 64 |
+
total_affected_guests += user_pools[pool]
|
| 65 |
|
| 66 |
+
st.write(f"In total, {total_affected_guests} are unable to eat this dish.")
|
| 67 |
|
| 68 |
|
| 69 |
# Text input for the search query
|
pages/user_0_event_participation.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from utils.allergens import *
|
| 3 |
+
from utils.variables import *
|
| 4 |
+
from utils.event_participation import *
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
user_id = 0
|
| 8 |
+
|
| 9 |
+
show_event_participation(user_id)
|
pages/user_3_profile.py
CHANGED
|
@@ -10,3 +10,4 @@ st.write("You can edit your profile below.")
|
|
| 10 |
|
| 11 |
create_allergy_input(3)
|
| 12 |
|
|
|
|
|
|
| 10 |
|
| 11 |
create_allergy_input(3)
|
| 12 |
|
| 13 |
+
|
utils/allergy_input.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from utils.allergens import *
|
| 3 |
from utils.variables import *
|
| 4 |
|
| 5 |
|
|
@@ -13,8 +13,17 @@ sensitivity_options = {
|
|
| 13 |
"Slightly sensitive": "Can eat food that has touched this ingredient"
|
| 14 |
}
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
st.write("Your allergies:")
|
| 19 |
for i in user_list[user_id].keys():
|
| 20 |
st.write(f"{i}, allergy degree: {user_list[user_id][i][0]}, can eat if cooked: {user_list[user_id][i][1]}")
|
|
@@ -33,8 +42,8 @@ def create_allergy_input(user_id, st=st):
|
|
| 33 |
import streamlit as st
|
| 34 |
|
| 35 |
# Sample data
|
| 36 |
-
#filtered_items = ["apple", "banana", "orange", "pear"]
|
| 37 |
-
#user_allergen_list = ["apple", "pear"] # Example of items in the user's allergen list
|
| 38 |
|
| 39 |
# Sensitivity options
|
| 40 |
sensitivity_options = {
|
|
@@ -50,64 +59,62 @@ def create_allergy_input(user_id, st=st):
|
|
| 50 |
none = []
|
| 51 |
|
| 52 |
# Initialize session state to store titles and selections for each expander
|
| 53 |
-
if "
|
| 54 |
-
st.session_state
|
| 55 |
-
if "
|
| 56 |
-
st.session_state
|
| 57 |
-
if "
|
| 58 |
-
st.session_state
|
| 59 |
|
| 60 |
# Function to update expander title based on selection
|
| 61 |
def update_title(item):
|
| 62 |
-
selections = st.session_state.get(f"{item}_radio", "None")
|
| 63 |
selection = "None"
|
| 64 |
if selections == "Extremely sensitive - " + sensitivity_options["Extremely sensitive"]:
|
| 65 |
selection = "Extremely sensitive🛑🚫"
|
| 66 |
-
user_list[user_id][item] = (3, st.session_state[f"{item}_checkbox"])
|
| 67 |
elif selections == "Sensitive - " + sensitivity_options["Sensitive"]:
|
| 68 |
selection = "Sensitive‼️"
|
| 69 |
-
user_list[user_id][item] = (2, st.session_state[f"{item}_checkbox"])
|
| 70 |
elif selections == "Slightly sensitive - " + sensitivity_options["Slightly sensitive"]:
|
| 71 |
selection = "Slightly sensitive❗"
|
| 72 |
-
user_list[user_id][item] = (1, st.session_state[f"{item}_checkbox"])
|
| 73 |
else:
|
| 74 |
user_list[user_id].pop(item)
|
| 75 |
|
| 76 |
-
|
| 77 |
if selection != "None":
|
| 78 |
-
st.session_state
|
| 79 |
else:
|
| 80 |
-
st.session_state
|
| 81 |
|
| 82 |
"""option = selection.split(" - ")
|
| 83 |
selection = option[1]"""
|
| 84 |
|
| 85 |
# Keep the expander open
|
| 86 |
-
st.session_state
|
| 87 |
-
|
| 88 |
|
| 89 |
# Loop through each item
|
| 90 |
for item in filtered_items:
|
| 91 |
# Check if the item is in the user's allergen list
|
| 92 |
-
#if item in user_allergen_list:
|
| 93 |
-
#key=f"{item}_radio"
|
| 94 |
-
title = st.session_state
|
| 95 |
with st.expander(title):
|
| 96 |
# Radio buttons for sensitivity level with a "None" option
|
| 97 |
sensitivity = st.radio(
|
| 98 |
f"Sensitivity level for {item.capitalize()}",
|
| 99 |
options=["None"] + [f"{level} - {description}" for level, description in sensitivity_options.items()],
|
| 100 |
-
key=f"{item}_radio",
|
| 101 |
on_change=lambda item=item: update_title(item) # Call update_title with the item argument
|
| 102 |
|
| 103 |
)
|
| 104 |
# Store the current selection in session_state for later access
|
| 105 |
-
st.session_state
|
| 106 |
|
| 107 |
# Checkbox to indicate if they can eat the ingredient if it's cooked
|
| 108 |
can_eat_if_cooked = st.checkbox(
|
| 109 |
"Can eat the ingredient if it is cooked",
|
| 110 |
-
key=f"{item}_checkbox"
|
| 111 |
)
|
| 112 |
|
| 113 |
"""else:
|
|
@@ -118,19 +125,19 @@ def create_allergy_input(user_id, st=st):
|
|
| 118 |
options=["None"] + [f"{level} - {description}" for level, description in sensitivity_options.items()],
|
| 119 |
key=f"{item}_radio"
|
| 120 |
)
|
| 121 |
-
|
| 122 |
# Checkbox to indicate if they can eat the ingredient if it's cooked
|
| 123 |
can_eat_if_cooked = st.checkbox(
|
| 124 |
"Can eat the ingredient if it is cooked",
|
| 125 |
key=f"{item}_checkbox"
|
| 126 |
)
|
| 127 |
-
|
| 128 |
# If a sensitivity other than "None" is selected, mark the item for addition to the allergen list
|
| 129 |
if sensitivity != "None":
|
| 130 |
to_add.append(item)"""
|
| 131 |
|
| 132 |
# Update user_allergen_list based on selections
|
| 133 |
-
#user_allergen_list = [item for item in user_allergen_list if item not in to_remove] + to_add
|
| 134 |
|
| 135 |
# Display updated allergen list
|
| 136 |
-
#st.write("Updated allergen list:", to_remove)
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from utils.allergens import *
|
| 3 |
from utils.variables import *
|
| 4 |
|
| 5 |
|
|
|
|
| 13 |
"Slightly sensitive": "Can eat food that has touched this ingredient"
|
| 14 |
}
|
| 15 |
|
| 16 |
+
|
| 17 |
+
def create_allergy_input(user_id):
|
| 18 |
+
import streamlit as st
|
| 19 |
+
|
| 20 |
+
#details_link = f"[Go to this user's event participation page {user_id}](?page=event%5Fparticipation&user_id={user_id})"
|
| 21 |
+
#details_link = f"[Go to this user's event participation page {user_id}](?page=event%5Fparticipation)"
|
| 22 |
+
#st.markdown(details_link, unsafe_allow_html=True)
|
| 23 |
+
|
| 24 |
+
page_1_link = "[Go to Page 1](?page=test)"
|
| 25 |
+
st.markdown(page_1_link, unsafe_allow_html=True)
|
| 26 |
+
|
| 27 |
st.write("Your allergies:")
|
| 28 |
for i in user_list[user_id].keys():
|
| 29 |
st.write(f"{i}, allergy degree: {user_list[user_id][i][0]}, can eat if cooked: {user_list[user_id][i][1]}")
|
|
|
|
| 42 |
import streamlit as st
|
| 43 |
|
| 44 |
# Sample data
|
| 45 |
+
# filtered_items = ["apple", "banana", "orange", "pear"]
|
| 46 |
+
# user_allergen_list = ["apple", "pear"] # Example of items in the user's allergen list
|
| 47 |
|
| 48 |
# Sensitivity options
|
| 49 |
sensitivity_options = {
|
|
|
|
| 59 |
none = []
|
| 60 |
|
| 61 |
# Initialize session state to store titles and selections for each expander
|
| 62 |
+
if f"{user_id}_expander_titles" not in st.session_state:
|
| 63 |
+
st.session_state[f"{user_id}_expander_titles"] = {item: item.capitalize() for item in filtered_items}
|
| 64 |
+
if "{user_id}_expander_selections" not in st.session_state:
|
| 65 |
+
st.session_state[f"{user_id}_expander_selections"] = {}
|
| 66 |
+
if "{user_id}_expanded_state" not in st.session_state:
|
| 67 |
+
st.session_state[f"{user_id}_expanded_state"] = {item: True for item in filtered_items} # Keep all expanders open initially
|
| 68 |
|
| 69 |
# Function to update expander title based on selection
|
| 70 |
def update_title(item):
|
| 71 |
+
selections = st.session_state.get(f"{user_id}_{item}_radio", "None")
|
| 72 |
selection = "None"
|
| 73 |
if selections == "Extremely sensitive - " + sensitivity_options["Extremely sensitive"]:
|
| 74 |
selection = "Extremely sensitive🛑🚫"
|
| 75 |
+
user_list[user_id][item] = (3, st.session_state[f"{user_id}_{item}_checkbox"])
|
| 76 |
elif selections == "Sensitive - " + sensitivity_options["Sensitive"]:
|
| 77 |
selection = "Sensitive‼️"
|
| 78 |
+
user_list[user_id][item] = (2, st.session_state[f"{user_id}_{item}_checkbox"])
|
| 79 |
elif selections == "Slightly sensitive - " + sensitivity_options["Slightly sensitive"]:
|
| 80 |
selection = "Slightly sensitive❗"
|
| 81 |
+
user_list[user_id][item] = (1, st.session_state[f"{user_id}_{item}_checkbox"])
|
| 82 |
else:
|
| 83 |
user_list[user_id].pop(item)
|
| 84 |
|
|
|
|
| 85 |
if selection != "None":
|
| 86 |
+
st.session_state[f"{user_id}_expander_titles"][item] = f"{item.capitalize()} - {selection}"
|
| 87 |
else:
|
| 88 |
+
st.session_state[f"{user_id}_expander_titles"][item] = item.capitalize() # Reset to default if "None" is selected
|
| 89 |
|
| 90 |
"""option = selection.split(" - ")
|
| 91 |
selection = option[1]"""
|
| 92 |
|
| 93 |
# Keep the expander open
|
| 94 |
+
st.session_state[f"{user_id}_expanded_state"][item] = True
|
|
|
|
| 95 |
|
| 96 |
# Loop through each item
|
| 97 |
for item in filtered_items:
|
| 98 |
# Check if the item is in the user's allergen list
|
| 99 |
+
# if item in user_allergen_list:
|
| 100 |
+
# key=f"{item}_radio"
|
| 101 |
+
title = st.session_state[f"{user_id}_expander_titles"][item]
|
| 102 |
with st.expander(title):
|
| 103 |
# Radio buttons for sensitivity level with a "None" option
|
| 104 |
sensitivity = st.radio(
|
| 105 |
f"Sensitivity level for {item.capitalize()}",
|
| 106 |
options=["None"] + [f"{level} - {description}" for level, description in sensitivity_options.items()],
|
| 107 |
+
key=f"{user_id}_{item}_radio",
|
| 108 |
on_change=lambda item=item: update_title(item) # Call update_title with the item argument
|
| 109 |
|
| 110 |
)
|
| 111 |
# Store the current selection in session_state for later access
|
| 112 |
+
st.session_state[f"{user_id}_expander_selections"][item] = sensitivity
|
| 113 |
|
| 114 |
# Checkbox to indicate if they can eat the ingredient if it's cooked
|
| 115 |
can_eat_if_cooked = st.checkbox(
|
| 116 |
"Can eat the ingredient if it is cooked",
|
| 117 |
+
key=f"{user_id}_{item}_checkbox"
|
| 118 |
)
|
| 119 |
|
| 120 |
"""else:
|
|
|
|
| 125 |
options=["None"] + [f"{level} - {description}" for level, description in sensitivity_options.items()],
|
| 126 |
key=f"{item}_radio"
|
| 127 |
)
|
| 128 |
+
|
| 129 |
# Checkbox to indicate if they can eat the ingredient if it's cooked
|
| 130 |
can_eat_if_cooked = st.checkbox(
|
| 131 |
"Can eat the ingredient if it is cooked",
|
| 132 |
key=f"{item}_checkbox"
|
| 133 |
)
|
| 134 |
+
|
| 135 |
# If a sensitivity other than "None" is selected, mark the item for addition to the allergen list
|
| 136 |
if sensitivity != "None":
|
| 137 |
to_add.append(item)"""
|
| 138 |
|
| 139 |
# Update user_allergen_list based on selections
|
| 140 |
+
# user_allergen_list = [item for item in user_allergen_list if item not in to_remove] + to_add
|
| 141 |
|
| 142 |
# Display updated allergen list
|
| 143 |
+
# st.write("Updated allergen list:", to_remove)
|
utils/event_participation.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from utils.allergens import *
|
| 3 |
+
from utils.variables import *
|
| 4 |
+
from utils.event_participation import *
|
| 5 |
+
|
| 6 |
+
def show_event_participation(user_id):
|
| 7 |
+
st.title("Event participation")
|
| 8 |
+
st.write("Welcome to the event!")
|
| 9 |
+
|
| 10 |
+
relevant_allergies = []
|
| 11 |
+
st.write("The dish served at the event will contain the following ingredients:")
|
| 12 |
+
for ingredient in ingredient_list:
|
| 13 |
+
st.write(ingredient)
|
| 14 |
+
for allergen in user_list[user_id].keys():
|
| 15 |
+
if allergen == ingredient:
|
| 16 |
+
relevant_allergies.append(ingredient)
|
| 17 |
+
#st.write(f"The dish will contain {ingredient}. You are allergic to {ingredient}.")
|
| 18 |
+
if len(relevant_allergies) == 0:
|
| 19 |
+
st.write("You can eat this dish!")
|
| 20 |
+
else:
|
| 21 |
+
st.write("You cannot eat this dish because it contains:")
|
| 22 |
+
for a in relevant_allergies:
|
| 23 |
+
st.write(a)
|