Spaces:
Running
Running
adrianpierce
commited on
Commit
•
60629d2
1
Parent(s):
b271415
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
# imports
|
2 |
import streamlit as st
|
3 |
import numpy as np
|
4 |
import pandas as pd
|
@@ -11,68 +10,10 @@ openai.api_key = st.secrets["open_ai_key"]
|
|
11 |
if 'gpt_response' not in st.session_state:
|
12 |
st.session_state.gpt_response = None
|
13 |
|
14 |
-
|
15 |
-
st.
|
16 |
-
user_direction = st.text_area(
|
17 |
-
"What do you want to cook? Describe anything - a dish, cuisine, event, or vibe.",
|
18 |
-
placeholder="quick snack, asian style bowl with either noodles or rice, something italian",
|
19 |
-
)
|
20 |
-
|
21 |
-
serving_size = st.number_input(
|
22 |
-
"How many people are you cooking for?",
|
23 |
-
min_value=1,
|
24 |
-
max_value=100,
|
25 |
-
value=2,
|
26 |
-
step=1
|
27 |
-
)
|
28 |
-
|
29 |
-
difficulty_dictionary = {
|
30 |
-
"Quick & Easy": {
|
31 |
-
"description": "Easy recipes with straightforward instructions. Ideal for beginners or those seeking quick and simple cooking.",
|
32 |
-
},
|
33 |
-
"Intermediate": {
|
34 |
-
"description": "Recipes with some intricate steps that invite a little challenge. Perfect for regular cooks wanting to expand their repertoire with new ingredients and techniques.",
|
35 |
-
},
|
36 |
-
"Professional": {
|
37 |
-
"description": "Complex recipes that demand a high level of skill and precision. Suited for seasoned cooks aspiring to professional-level sophistication and creativity.",
|
38 |
-
}
|
39 |
-
}
|
40 |
-
|
41 |
-
selected_difficulty = st.radio(
|
42 |
-
"Choose a difficulty level for your recipe.",
|
43 |
-
[
|
44 |
-
list(difficulty_dictionary.keys())[0],
|
45 |
-
list(difficulty_dictionary.keys())[1],
|
46 |
-
list(difficulty_dictionary.keys())[2]
|
47 |
-
],
|
48 |
-
captions = [
|
49 |
-
difficulty_dictionary["Quick & Easy"]["description"],
|
50 |
-
difficulty_dictionary["Intermediate"]["description"],
|
51 |
-
difficulty_dictionary["Professional"]["description"]
|
52 |
-
]
|
53 |
-
)
|
54 |
-
|
55 |
-
exclusions = st.text_area(
|
56 |
-
"Any ingredients you want to exclude?",
|
57 |
-
placeholder="gluten, dairy, nuts, cilantro",
|
58 |
-
)
|
59 |
-
|
60 |
-
fancy_exclusions =""
|
61 |
-
|
62 |
-
if selected_difficulty == "Professional":
|
63 |
-
exclude_fancy = st.checkbox(
|
64 |
-
"Exclude cliche professional ingredients? (gold leaf, truffle, edible flowers, microgreens)",
|
65 |
-
value=True)
|
66 |
-
fancy_exclusions = "gold leaf, truffle, edible flowers, microgreens"
|
67 |
-
|
68 |
-
|
69 |
-
user_inputs = {
|
70 |
-
"user_direction" : user_direction,
|
71 |
-
"exclusions": f"{exclusions}, {fancy_exclusions}",
|
72 |
-
"serving_size": serving_size,
|
73 |
-
"difficulty": selected_difficulty
|
74 |
-
}
|
75 |
|
|
|
76 |
def create_detailed_prompt(user_direction, exclusions, serving_size, difficulty):
|
77 |
if difficulty == "Quick & Easy":
|
78 |
prompt = (
|
@@ -98,7 +39,7 @@ def create_detailed_prompt(user_direction, exclusions, serving_size, difficulty)
|
|
98 |
return prompt
|
99 |
|
100 |
def generate_recipe(user_inputs):
|
101 |
-
with st.spinner('Building the perfect recipe
|
102 |
functions = [
|
103 |
{
|
104 |
"name": "provide_recipe",
|
@@ -163,6 +104,72 @@ def generate_recipe(user_inputs):
|
|
163 |
function_call={"name":"provide_recipe"}, # auto is default, but we'll be explicit
|
164 |
)
|
165 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
|
167 |
st.button(label='Submit', on_click=generate_recipe, kwargs=dict(user_inputs=user_inputs))
|
168 |
|
@@ -187,4 +194,5 @@ if st.session_state.gpt_response is not None:
|
|
187 |
md_instructions += f"{instruction['step_number']}. {instruction['instruction']} \n"
|
188 |
st.markdown(md_instructions)
|
189 |
except:
|
190 |
-
st.write(loaded_recipe['instructions'])
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import numpy as np
|
3 |
import pandas as pd
|
|
|
10 |
if 'gpt_response' not in st.session_state:
|
11 |
st.session_state.gpt_response = None
|
12 |
|
13 |
+
if "copied" not in st.session_state:
|
14 |
+
st.session_state.copied = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
+
# functions
|
17 |
def create_detailed_prompt(user_direction, exclusions, serving_size, difficulty):
|
18 |
if difficulty == "Quick & Easy":
|
19 |
prompt = (
|
|
|
39 |
return prompt
|
40 |
|
41 |
def generate_recipe(user_inputs):
|
42 |
+
with st.spinner('Building the perfect recipe...'):
|
43 |
functions = [
|
44 |
{
|
45 |
"name": "provide_recipe",
|
|
|
104 |
function_call={"name":"provide_recipe"}, # auto is default, but we'll be explicit
|
105 |
)
|
106 |
|
107 |
+
def on_copy_click(text):
|
108 |
+
st.session_state.copied.append(text)
|
109 |
+
clipboard.copy(text)
|
110 |
+
st.toast(f"Copied to clipboard!", icon='✅' )
|
111 |
+
|
112 |
+
# app
|
113 |
+
st.title("Let's get cooking")
|
114 |
+
user_direction = st.text_area(
|
115 |
+
"What do you want to cook? Describe anything - a dish, cuisine, event, or vibe.",
|
116 |
+
placeholder="quick snack, asian style bowl with either noodles or rice, something italian",
|
117 |
+
)
|
118 |
+
|
119 |
+
serving_size = st.number_input(
|
120 |
+
"How many servings would you like to cook?",
|
121 |
+
min_value=1,
|
122 |
+
max_value=100,
|
123 |
+
value=2,
|
124 |
+
step=1
|
125 |
+
)
|
126 |
+
|
127 |
+
difficulty_dictionary = {
|
128 |
+
"Quick & Easy": {
|
129 |
+
"description": "Easy recipes with straightforward instructions. Ideal for beginners or those seeking quick and simple cooking.",
|
130 |
+
},
|
131 |
+
"Intermediate": {
|
132 |
+
"description": "Recipes with some intricate steps that invite a little challenge. Perfect for regular cooks wanting to expand their repertoire with new ingredients and techniques.",
|
133 |
+
},
|
134 |
+
"Professional": {
|
135 |
+
"description": "Complex recipes that demand a high level of skill and precision. Suited for seasoned cooks aspiring to professional-level sophistication and creativity.",
|
136 |
+
}
|
137 |
+
}
|
138 |
+
|
139 |
+
selected_difficulty = st.radio(
|
140 |
+
"Choose a difficulty level for your recipe.",
|
141 |
+
[
|
142 |
+
list(difficulty_dictionary.keys())[0],
|
143 |
+
list(difficulty_dictionary.keys())[1],
|
144 |
+
list(difficulty_dictionary.keys())[2]
|
145 |
+
],
|
146 |
+
captions = [
|
147 |
+
difficulty_dictionary["Quick & Easy"]["description"],
|
148 |
+
difficulty_dictionary["Intermediate"]["description"],
|
149 |
+
difficulty_dictionary["Professional"]["description"]
|
150 |
+
]
|
151 |
+
)
|
152 |
+
|
153 |
+
exclusions = st.text_area(
|
154 |
+
"Any ingredients you want to exclude?",
|
155 |
+
placeholder="gluten, dairy, nuts, cilantro",
|
156 |
+
)
|
157 |
+
|
158 |
+
fancy_exclusions =""
|
159 |
+
|
160 |
+
if selected_difficulty == "Professional":
|
161 |
+
exclude_fancy = st.checkbox(
|
162 |
+
"Exclude cliche professional ingredients? (gold leaf, truffle, edible flowers, microgreens)",
|
163 |
+
value=True)
|
164 |
+
fancy_exclusions = "gold leaf, truffle, edible flowers, microgreens"
|
165 |
+
|
166 |
+
|
167 |
+
user_inputs = {
|
168 |
+
"user_direction" : user_direction,
|
169 |
+
"exclusions": f"{exclusions}, {fancy_exclusions}",
|
170 |
+
"serving_size": serving_size,
|
171 |
+
"difficulty": selected_difficulty
|
172 |
+
}
|
173 |
|
174 |
st.button(label='Submit', on_click=generate_recipe, kwargs=dict(user_inputs=user_inputs))
|
175 |
|
|
|
194 |
md_instructions += f"{instruction['step_number']}. {instruction['instruction']} \n"
|
195 |
st.markdown(md_instructions)
|
196 |
except:
|
197 |
+
st.write(loaded_recipe['instructions'])
|
198 |
+
# st.button("📋", on_click=on_copy_click, args=(full_response,))
|