Spaces:
Configuration error
Configuration error
import streamlit as st | |
from utils.allergens import * | |
from utils.variables import * | |
st.title("Dish planning") | |
st.write("Welcome to the dish planning page!") | |
#for u in user_list.keys(): | |
# for i in user_list[u].keys(): | |
# st.write(f"user id: {u}, i: {i}") | |
# for i in user_list[u][i]: | |
# st.write(i) | |
#Behöver lägga till om den tillagas eller ej? | |
col1, col2 = st.columns(2) | |
with col1: | |
c = ''' | |
st.header("Ingredients:") | |
for i in ingredient_list: | |
allergic_people_count = 0 | |
for u in user_list.values(): | |
if i in u.keys(): | |
allergic_people_count += 1 | |
else: | |
found = False | |
for s in synonyms[i]: | |
if found: | |
break | |
else: | |
if s in u.keys(): | |
allergic_people_count += 1 | |
found = True | |
break | |
if allergic_people_count > 0: | |
st.write(f"{i} - {allergic_people_count} guest{'s are' if allergic_people_count > 1 else ' is'} sensitive to this ingredient") | |
else: | |
st.write(f"{i}") | |
''' | |
st.header("Ingredients:") | |
for i in ingredient_list.keys(): | |
allergic_people_count = 0 | |
for u in user_list.values(): | |
if i in u.keys(): | |
if ingredient_list[i] == False: # Raw, does not matter if the guest can eat it cooked | |
allergic_people_count += 1 | |
elif u[i][1] == False: # The ingredient is cooked but the guest can still not eat it | |
allergic_people_count += 1 | |
else: | |
found = False | |
for s in synonyms[i]: | |
if found: | |
break | |
else: | |
if s in u.keys(): | |
if ingredient_list[i] == False: #Raw, does not matter if the guest can eat it cooked | |
allergic_people_count += 1 | |
else: | |
if u[s][1] == False: #The ingredient is cooked but the guest can still not eat it | |
allergic_people_count += 1 | |
#allergic_people_count += 1 | |
found = True | |
break | |
if allergic_people_count > 0: | |
st.write(f"{i} - {allergic_people_count} guest{'s are' if allergic_people_count > 1 else ' is'} sensitive to this ingredient") | |
else: | |
st.write(f"{i}") | |
with col2: | |
c = ''' | |
st.header("Aggregate:") | |
user_pools = defaultdict(lambda: False) | |
# Summary of allergies | |
for user_id in user_list.keys(): | |
relevant_allergy_list = "" | |
for ingredient in ingredient_list: | |
if ingredient in user_list[user_id].keys(): | |
if relevant_allergy_list == "": | |
relevant_allergy_list = relevant_allergy_list + ingredient | |
else: | |
relevant_allergy_list = relevant_allergy_list + ", " + ingredient | |
else: | |
for s in synonyms[i]: | |
found = False | |
if found: | |
break | |
else: | |
if s in user_list[user_id].keys(): | |
if relevant_allergy_list == "": | |
relevant_allergy_list = relevant_allergy_list + ingredient | |
else: | |
relevant_allergy_list = relevant_allergy_list + ", " + ingredient | |
found = True | |
break | |
if not relevant_allergy_list == "": | |
if not user_pools[relevant_allergy_list]: | |
user_pools[relevant_allergy_list] = 1 | |
else: | |
user_pools[relevant_allergy_list] += 1 | |
total_affected_guests = 0 | |
for pool in user_pools.keys(): | |
#relevant_allergies = pool.split(",") | |
st.write(f"{user_pools[pool]} user{'s' if user_pools[pool] == 1 else ''} cannot eat {pool}") | |
total_affected_guests += user_pools[pool] | |
st.write(f"In total, {total_affected_guests} {'is' if total_affected_guests == 1 else 'are'} unable to eat this dish.") | |
''' | |
st.header("Aggregate:") | |
user_pools = defaultdict(lambda: False) | |
# Summary of allergies | |
for user_id in user_list.keys(): | |
relevant_allergy_list = "" | |
for ingredient in ingredient_list.keys(): | |
if ingredient in user_list[user_id].keys(): | |
if not ingredient_list[ingredient]: #Raw | |
if relevant_allergy_list == "": | |
relevant_allergy_list = relevant_allergy_list + ingredient | |
else: | |
relevant_allergy_list = relevant_allergy_list + ", " + ingredient | |
elif not user_list[user_id][ingredient][1]: #cooked, but can still not eat | |
if relevant_allergy_list == "": | |
relevant_allergy_list = relevant_allergy_list + ingredient | |
else: | |
relevant_allergy_list = relevant_allergy_list + ", " + ingredient | |
else: | |
for s in synonyms[ingredient]: | |
#if found: | |
#break | |
#else: | |
if s in user_list[user_id].keys(): | |
if ingredient_list[ingredient] == False: # Raw, does not matter if the guest can eat it cooked | |
if relevant_allergy_list == "": | |
relevant_allergy_list = relevant_allergy_list + ingredient | |
else: | |
relevant_allergy_list = relevant_allergy_list + ", " + ingredient | |
#found = True | |
#break | |
elif user_list[user_id][s][1] == False: # The ingredient is cooked but the guest can still not eat it | |
if relevant_allergy_list == "": | |
relevant_allergy_list = relevant_allergy_list + ingredient | |
else: | |
relevant_allergy_list = relevant_allergy_list + ", " + ingredient | |
#found = True | |
#break | |
if not relevant_allergy_list == "": | |
if not user_pools[relevant_allergy_list]: | |
user_pools[relevant_allergy_list] = 1 | |
else: | |
user_pools[relevant_allergy_list] += 1 | |
total_affected_guests = 0 | |
for pool in user_pools.keys(): | |
#relevant_allergies = pool.split(",") | |
st.write(f"{user_pools[pool]} user{'s' if user_pools[pool] == 1 else ''} cannot eat {pool}") | |
total_affected_guests += user_pools[pool] | |
st.write(f"In total, {total_affected_guests} {'is' if total_affected_guests == 1 else 'are'} unable to eat this dish.") | |
# Text input for the search query | |
query = st.text_input("Search for an ingredient:") | |
# Filter the list based on the search query | |
if query: | |
filtered_items = [allergen for allergen in allergens if query.lower() in allergen.lower()] | |
else: | |
filtered_items = allergens | |
#def update_cook(item): | |
# prev = ingredient_list[item] | |
# ingredient_list[item] = not prev | |
def update_cook(item): | |
ingredient_list[item] = (st.session_state[f"{item}_cooked"]) | |
# Display the filtered list | |
st.write("Results:") | |
for item in filtered_items: | |
if item in ingredient_list: | |
if st.button(f"- {item} (this is in your food)"): | |
#ingredient_list.remove(item) | |
ingredient_list.pop(item) | |
st.rerun() | |
if_cooked = st.checkbox( | |
"The ingredient will be cooked", | |
key=f"{item}_cooked", | |
on_change=lambda item=item: update_cook(item), | |
value=ingredient_list[item] | |
) | |
else: | |
if st.button(f"- {item}"): | |
#ingredient_list.append(item) | |
ingredient_list[item] = False | |
st.rerun() | |