Spaces:
Configuration error
Configuration error
Starting individual user profile pages.
Browse files- pages/allergy-input.py +0 -130
- pages/user_0_profile.py +2 -2
- utils/allergy-input.py +136 -0
- utils/variables.py +6 -2
pages/allergy-input.py
DELETED
|
@@ -1,130 +0,0 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
from utils.allergens import * #Vill uppdatera denna till en dict med allergenen och sen ett värde mellan 0-3? #Hur hantera tillagad?
|
| 3 |
-
from utils.variables import *
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
st.title("Allergy input")
|
| 7 |
-
st.write("Welcome to the allergy input page!")
|
| 8 |
-
|
| 9 |
-
# Options for the sensitivity level with descriptions
|
| 10 |
-
sensitivity_options = {
|
| 11 |
-
"Extremely sensitive": "Cannot eat food prepared in the same kitchen as this ingredient",
|
| 12 |
-
"Sensitive": "Cannot eat food containing this ingredient",
|
| 13 |
-
"Slightly sensitive": "Can eat food that has touched this ingredient"
|
| 14 |
-
}
|
| 15 |
-
|
| 16 |
-
st.write("Your allergies:")
|
| 17 |
-
for i in user_allergen_list:
|
| 18 |
-
st.write(i)
|
| 19 |
-
|
| 20 |
-
# Text input for the search query
|
| 21 |
-
query = st.text_input("Search for an allergy:")
|
| 22 |
-
|
| 23 |
-
# Filter the list based on the search query
|
| 24 |
-
if query:
|
| 25 |
-
filtered_items = [allergen for allergen in allergens if query.lower() in allergen.lower()]
|
| 26 |
-
else:
|
| 27 |
-
filtered_items = allergens
|
| 28 |
-
|
| 29 |
-
# Display the filtered list
|
| 30 |
-
st.write("Results:")
|
| 31 |
-
import streamlit as st
|
| 32 |
-
|
| 33 |
-
# Sample data
|
| 34 |
-
#filtered_items = ["apple", "banana", "orange", "pear"]
|
| 35 |
-
#user_allergen_list = ["apple", "pear"] # Example of items in the user's allergen list
|
| 36 |
-
|
| 37 |
-
# Sensitivity options
|
| 38 |
-
sensitivity_options = {
|
| 39 |
-
"Extremely sensitive": "Cannot eat food prepared in the same kitchen as this ingredient",
|
| 40 |
-
"Sensitive": "Cannot eat food containing this ingredient",
|
| 41 |
-
"Slightly sensitive": "Can eat food that has touched this ingredient"
|
| 42 |
-
}
|
| 43 |
-
|
| 44 |
-
# Temporary list to track modifications
|
| 45 |
-
extreme = []
|
| 46 |
-
sensitive = []
|
| 47 |
-
light = []
|
| 48 |
-
none = []
|
| 49 |
-
|
| 50 |
-
# Initialize session state to store titles and selections for each expander
|
| 51 |
-
if "expander_titles" not in st.session_state:
|
| 52 |
-
st.session_state.expander_titles = {item: item.capitalize() for item in filtered_items}
|
| 53 |
-
if "expander_selections" not in st.session_state:
|
| 54 |
-
st.session_state.expander_selections = {}
|
| 55 |
-
if "expanded_state" not in st.session_state:
|
| 56 |
-
st.session_state.expanded_state = {item: True for item in filtered_items} # Keep all expanders open initially
|
| 57 |
-
|
| 58 |
-
# Function to update expander title based on selection
|
| 59 |
-
def update_title(item):
|
| 60 |
-
selections = st.session_state.get(f"{item}_radio", "None")
|
| 61 |
-
selection = "None"
|
| 62 |
-
if selections == "Extremely sensitive - " + sensitivity_options["Extremely sensitive"]:
|
| 63 |
-
selection = "Extremely sensitive🛑🚫"
|
| 64 |
-
elif selections == "Sensitive - " + sensitivity_options["Sensitive"]:
|
| 65 |
-
selection = "Sensitive‼️"
|
| 66 |
-
elif selections == "Slightly sensitive - " + sensitivity_options["Slightly sensitive"]:
|
| 67 |
-
selection = "Slightly sensitive❗"
|
| 68 |
-
#else:
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
if selection != "None":
|
| 72 |
-
st.session_state.expander_titles[item] = f"{item.capitalize()} - {selection}"
|
| 73 |
-
else:
|
| 74 |
-
st.session_state.expander_titles[item] = item.capitalize() # Reset to default if "None" is selected
|
| 75 |
-
|
| 76 |
-
"""option = selection.split(" - ")
|
| 77 |
-
selection = option[1]"""
|
| 78 |
-
|
| 79 |
-
# Keep the expander open
|
| 80 |
-
st.session_state.expanded_state[item] = True
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
# Loop through each item
|
| 84 |
-
for item in filtered_items:
|
| 85 |
-
# Check if the item is in the user's allergen list
|
| 86 |
-
#if item in user_allergen_list:
|
| 87 |
-
#key=f"{item}_radio"
|
| 88 |
-
title = st.session_state.expander_titles[item]
|
| 89 |
-
with st.expander(title):
|
| 90 |
-
# Radio buttons for sensitivity level with a "None" option
|
| 91 |
-
sensitivity = st.radio(
|
| 92 |
-
f"Sensitivity level for {item.capitalize()}",
|
| 93 |
-
options=["None"] + [f"{level} - {description}" for level, description in sensitivity_options.items()],
|
| 94 |
-
key=f"{item}_radio",
|
| 95 |
-
on_change=lambda item=item: update_title(item) # Call update_title with the item argument
|
| 96 |
-
|
| 97 |
-
)
|
| 98 |
-
# Store the current selection in session_state for later access
|
| 99 |
-
st.session_state.expander_selections[item] = sensitivity
|
| 100 |
-
|
| 101 |
-
# Checkbox to indicate if they can eat the ingredient if it's cooked
|
| 102 |
-
can_eat_if_cooked = st.checkbox(
|
| 103 |
-
"Can eat the ingredient if it is cooked",
|
| 104 |
-
key=f"{item}_checkbox"
|
| 105 |
-
)
|
| 106 |
-
|
| 107 |
-
"""else:
|
| 108 |
-
with st.expander(item.capitalize()):
|
| 109 |
-
# Radio buttons for sensitivity level with a "None" option
|
| 110 |
-
sensitivity = st.radio(
|
| 111 |
-
f"Sensitivity level for {item.capitalize()}",
|
| 112 |
-
options=["None"] + [f"{level} - {description}" for level, description in sensitivity_options.items()],
|
| 113 |
-
key=f"{item}_radio"
|
| 114 |
-
)
|
| 115 |
-
|
| 116 |
-
# Checkbox to indicate if they can eat the ingredient if it's cooked
|
| 117 |
-
can_eat_if_cooked = st.checkbox(
|
| 118 |
-
"Can eat the ingredient if it is cooked",
|
| 119 |
-
key=f"{item}_checkbox"
|
| 120 |
-
)
|
| 121 |
-
|
| 122 |
-
# If a sensitivity other than "None" is selected, mark the item for addition to the allergen list
|
| 123 |
-
if sensitivity != "None":
|
| 124 |
-
to_add.append(item)"""
|
| 125 |
-
|
| 126 |
-
# Update user_allergen_list based on selections
|
| 127 |
-
#user_allergen_list = [item for item in user_allergen_list if item not in to_remove] + to_add
|
| 128 |
-
|
| 129 |
-
# Display updated allergen list
|
| 130 |
-
#st.write("Updated allergen list:", to_remove)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pages/user_0_profile.py
CHANGED
|
@@ -1,12 +1,12 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from utils.allergens import *
|
| 3 |
from utils.variables import *
|
| 4 |
-
from
|
| 5 |
|
| 6 |
|
| 7 |
st.title("Allergy input")
|
| 8 |
st.write("Welcome to the allergy input page!")
|
| 9 |
st.write("You can edit your profile below.")
|
| 10 |
|
| 11 |
-
|
| 12 |
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from utils.allergens import *
|
| 3 |
from utils.variables import *
|
| 4 |
+
from utils.allergy-input import *
|
| 5 |
|
| 6 |
|
| 7 |
st.title("Allergy input")
|
| 8 |
st.write("Welcome to the allergy input page!")
|
| 9 |
st.write("You can edit your profile below.")
|
| 10 |
|
| 11 |
+
create_allergy_input(0)
|
| 12 |
|
utils/allergy-input.py
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from utils.allergens import * #Vill uppdatera denna till en dict med allergenen och sen ett värde mellan 0-3? #Hur hantera tillagad?
|
| 3 |
+
from utils.variables import *
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
st.title("Allergy input")
|
| 7 |
+
st.write("Welcome to the allergy input page!")
|
| 8 |
+
|
| 9 |
+
# Options for the sensitivity level with descriptions
|
| 10 |
+
sensitivity_options = {
|
| 11 |
+
"Extremely sensitive": "Cannot eat food prepared in the same kitchen as this ingredient",
|
| 12 |
+
"Sensitive": "Cannot eat food containing this ingredient",
|
| 13 |
+
"Slightly sensitive": "Can eat food that has touched this ingredient"
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
def create_allergy_input(user_id):
|
| 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]}")
|
| 21 |
+
|
| 22 |
+
# Text input for the search query
|
| 23 |
+
query = st.text_input("Search for an allergy:")
|
| 24 |
+
|
| 25 |
+
# Filter the list based on the search query
|
| 26 |
+
if query:
|
| 27 |
+
filtered_items = [allergen for allergen in allergens if query.lower() in allergen.lower()]
|
| 28 |
+
else:
|
| 29 |
+
filtered_items = allergens
|
| 30 |
+
|
| 31 |
+
# Display the filtered list
|
| 32 |
+
st.write("Results:")
|
| 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 = {
|
| 41 |
+
"Extremely sensitive": "Cannot eat food prepared in the same kitchen as this ingredient",
|
| 42 |
+
"Sensitive": "Cannot eat food containing this ingredient",
|
| 43 |
+
"Slightly sensitive": "Can eat food that has touched this ingredient"
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
# Temporary list to track modifications
|
| 47 |
+
extreme = []
|
| 48 |
+
sensitive = []
|
| 49 |
+
light = []
|
| 50 |
+
none = []
|
| 51 |
+
|
| 52 |
+
# Initialize session state to store titles and selections for each expander
|
| 53 |
+
if "expander_titles" not in st.session_state:
|
| 54 |
+
st.session_state.expander_titles = {item: item.capitalize() for item in filtered_items}
|
| 55 |
+
if "expander_selections" not in st.session_state:
|
| 56 |
+
st.session_state.expander_selections = {}
|
| 57 |
+
if "expanded_state" not in st.session_state:
|
| 58 |
+
st.session_state.expanded_state = {item: True for item in filtered_items} # Keep all expanders open initially
|
| 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] = (3, st.session_state[f"{item}_checkbox"])
|
| 67 |
+
elif selections == "Sensitive - " + sensitivity_options["Sensitive"]:
|
| 68 |
+
selection = "Sensitive‼️"
|
| 69 |
+
user_list[user_id] = (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] = (1, st.session_state[f"{item}_checkbox"])
|
| 73 |
+
else:
|
| 74 |
+
user_list[user_id] = (0, st.session_state[f"{item}_checkbox"])
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
if selection != "None":
|
| 78 |
+
st.session_state.expander_titles[item] = f"{item.capitalize()} - {selection}"
|
| 79 |
+
else:
|
| 80 |
+
st.session_state.expander_titles[item] = item.capitalize() # Reset to default if "None" is selected
|
| 81 |
+
|
| 82 |
+
"""option = selection.split(" - ")
|
| 83 |
+
selection = option[1]"""
|
| 84 |
+
|
| 85 |
+
# Keep the expander open
|
| 86 |
+
st.session_state.expanded_state[item] = True
|
| 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.expander_titles[item]
|
| 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.expander_selections[item] = sensitivity
|
| 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:
|
| 114 |
+
with st.expander(item.capitalize()):
|
| 115 |
+
# Radio buttons for sensitivity level with a "None" option
|
| 116 |
+
sensitivity = st.radio(
|
| 117 |
+
f"Sensitivity level for {item.capitalize()}",
|
| 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)
|
utils/variables.py
CHANGED
|
@@ -4,8 +4,6 @@ from collections import defaultdict
|
|
| 4 |
#user_allergen_list = ["Gluten"]
|
| 5 |
ingredient_list = ["Egg"]
|
| 6 |
|
| 7 |
-
user_allergen_list = []
|
| 8 |
-
|
| 9 |
# Init user profiles
|
| 10 |
|
| 11 |
user_0_list = defaultdict(lambda: (0, False))
|
|
@@ -14,3 +12,9 @@ user_2_list = defaultdict(lambda: (0, False))
|
|
| 14 |
user_3_list = defaultdict(lambda: (0, False))
|
| 15 |
|
| 16 |
user_0_list["Gluten"] = (2, False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
#user_allergen_list = ["Gluten"]
|
| 5 |
ingredient_list = ["Egg"]
|
| 6 |
|
|
|
|
|
|
|
| 7 |
# Init user profiles
|
| 8 |
|
| 9 |
user_0_list = defaultdict(lambda: (0, False))
|
|
|
|
| 12 |
user_3_list = defaultdict(lambda: (0, False))
|
| 13 |
|
| 14 |
user_0_list["Gluten"] = (2, False)
|
| 15 |
+
|
| 16 |
+
user_list = {}
|
| 17 |
+
user_list[0] = user_0_list
|
| 18 |
+
user_list[1] = user_1_list
|
| 19 |
+
user_list[2] = user_2_list
|
| 20 |
+
user_list[3] = user_3_list
|