Spaces:
Running
Running
adrianpierce
commited on
Commit
•
9dfc4e2
1
Parent(s):
64d25d9
Update Home.py
Browse files
Home.py
CHANGED
@@ -20,6 +20,16 @@ if 'recipe_saved' not in st.session_state:
|
|
20 |
if 'user_direction' not in st.session_state:
|
21 |
st.session_state.user_direction = None
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
# functions
|
24 |
def create_detailed_prompt(user_direction, exclusions, serving_size, difficulty):
|
25 |
if difficulty == "Quick & Easy":
|
@@ -130,6 +140,9 @@ def save_recipe():
|
|
130 |
|
131 |
def clear_inputs():
|
132 |
st.session_state.user_direction = None
|
|
|
|
|
|
|
133 |
|
134 |
# app
|
135 |
st.title("Let's get cooking")
|
@@ -139,7 +152,7 @@ st.session_state.user_direction = st.text_area(
|
|
139 |
placeholder="quick snack, asian style bowl with either noodles or rice, something italian",
|
140 |
)
|
141 |
|
142 |
-
serving_size = st.number_input(
|
143 |
"How many servings would you like to cook?",
|
144 |
min_value=1,
|
145 |
max_value=100,
|
@@ -159,7 +172,7 @@ difficulty_dictionary = {
|
|
159 |
}
|
160 |
}
|
161 |
|
162 |
-
selected_difficulty = st.radio(
|
163 |
"Choose a difficulty level for your recipe.",
|
164 |
[
|
165 |
list(difficulty_dictionary.keys())[0],
|
@@ -170,11 +183,13 @@ selected_difficulty = st.radio(
|
|
170 |
difficulty_dictionary["Quick & Easy"]["description"],
|
171 |
difficulty_dictionary["Intermediate"]["description"],
|
172 |
difficulty_dictionary["Professional"]["description"]
|
173 |
-
]
|
|
|
174 |
)
|
175 |
|
176 |
-
exclusions = st.text_area(
|
177 |
"Any ingredients you want to exclude?",
|
|
|
178 |
placeholder="gluten, dairy, nuts, cilantro",
|
179 |
)
|
180 |
|
@@ -189,13 +204,16 @@ if selected_difficulty == "Professional":
|
|
189 |
|
190 |
user_inputs = {
|
191 |
"user_direction" : st.session_state.user_direction,
|
192 |
-
"exclusions": f"{exclusions}, {fancy_exclusions}",
|
193 |
-
"serving_size": serving_size,
|
194 |
-
"difficulty": selected_difficulty
|
195 |
}
|
196 |
|
197 |
-
|
198 |
-
|
|
|
|
|
|
|
199 |
|
200 |
if st.session_state.gpt_response is not None:
|
201 |
st.divider()
|
|
|
20 |
if 'user_direction' not in st.session_state:
|
21 |
st.session_state.user_direction = None
|
22 |
|
23 |
+
if 'serving_size' not in st.session_state:
|
24 |
+
st.session_state.serving_size = 2
|
25 |
+
|
26 |
+
if 'selected_difficulty' not in st.session_state:
|
27 |
+
st.session_state.selected_difficulty = 0
|
28 |
+
|
29 |
+
if 'exclusions' not in st.session_state:
|
30 |
+
st.session_state.exclusions = None
|
31 |
+
|
32 |
+
|
33 |
# functions
|
34 |
def create_detailed_prompt(user_direction, exclusions, serving_size, difficulty):
|
35 |
if difficulty == "Quick & Easy":
|
|
|
140 |
|
141 |
def clear_inputs():
|
142 |
st.session_state.user_direction = None
|
143 |
+
st.session_state.exclusions = None
|
144 |
+
st.session_state.serving_size = 2
|
145 |
+
st.session_state.selected_difficulty = "Quick & Easy"
|
146 |
|
147 |
# app
|
148 |
st.title("Let's get cooking")
|
|
|
152 |
placeholder="quick snack, asian style bowl with either noodles or rice, something italian",
|
153 |
)
|
154 |
|
155 |
+
st.session_state.serving_size = st.number_input(
|
156 |
"How many servings would you like to cook?",
|
157 |
min_value=1,
|
158 |
max_value=100,
|
|
|
172 |
}
|
173 |
}
|
174 |
|
175 |
+
st.session_state.selected_difficulty = st.radio(
|
176 |
"Choose a difficulty level for your recipe.",
|
177 |
[
|
178 |
list(difficulty_dictionary.keys())[0],
|
|
|
183 |
difficulty_dictionary["Quick & Easy"]["description"],
|
184 |
difficulty_dictionary["Intermediate"]["description"],
|
185 |
difficulty_dictionary["Professional"]["description"]
|
186 |
+
],
|
187 |
+
index=list(difficulty_dictionary).index(st.session_state.selected_difficulty)
|
188 |
)
|
189 |
|
190 |
+
st.session_state.exclusions = st.text_area(
|
191 |
"Any ingredients you want to exclude?",
|
192 |
+
value = st.session_state.exclusions,
|
193 |
placeholder="gluten, dairy, nuts, cilantro",
|
194 |
)
|
195 |
|
|
|
204 |
|
205 |
user_inputs = {
|
206 |
"user_direction" : st.session_state.user_direction,
|
207 |
+
"exclusions": f"{st.session_state.exclusions}, {fancy_exclusions}",
|
208 |
+
"serving_size": st.session_state.serving_size,
|
209 |
+
"difficulty": st.session_state.selected_difficulty
|
210 |
}
|
211 |
|
212 |
+
col1, col2 = st.columns(2)
|
213 |
+
with col1:
|
214 |
+
st.button(label='Submit', on_click=generate_recipe, kwargs=dict(user_inputs=user_inputs), type="primary")
|
215 |
+
with col2:
|
216 |
+
st.button(label='Reset', on_click=clear_inputs, type="secondary")
|
217 |
|
218 |
if st.session_state.gpt_response is not None:
|
219 |
st.divider()
|