Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -54,6 +54,7 @@ def create_detailed_prompt(user_direction, exclusions, serving_size, difficulty)
|
|
54 |
def generate_recipe(user_inputs):
|
55 |
with st.spinner('Building the perfect recipe...'):
|
56 |
prompt = create_detailed_prompt(user_inputs['user_direction'], user_inputs['exclusions'], user_inputs['serving_size'], user_inputs['difficulty'])
|
|
|
57 |
functions = [
|
58 |
{
|
59 |
"name": "provide_recipe",
|
@@ -108,27 +109,26 @@ def generate_recipe(user_inputs):
|
|
108 |
}
|
109 |
]
|
110 |
|
111 |
-
prompt += f"\nPlease format the output in JSON. The JSON should include fields for 'name', 'description', 'ingredients', and 'instructions', with each field structured as described below.\n\n{functions}"
|
112 |
-
|
113 |
-
|
114 |
generate_kwargs = dict(
|
115 |
temperature=0.9,
|
116 |
-
|
117 |
top_p=0.9,
|
118 |
-
|
119 |
-
|
120 |
)
|
121 |
|
122 |
-
|
|
|
|
|
123 |
st.session_state.recipe = response
|
124 |
st.session_state.recipe_saved = False
|
125 |
-
|
126 |
def clear_inputs():
|
127 |
st.session_state.user_direction = None
|
128 |
st.session_state.exclusions = None
|
129 |
st.session_state.serving_size = 2
|
130 |
st.session_state.selected_difficulty = "Quick & Easy"
|
131 |
-
|
132 |
st.title("Let's get cooking")
|
133 |
st.session_state.user_direction = st.text_area(
|
134 |
"What do you want to cook? Describe anything - a dish, cuisine, event, or vibe.",
|
@@ -159,12 +159,12 @@ difficulty_dictionary = {
|
|
159 |
st.session_state.selected_difficulty = st.radio(
|
160 |
"Choose a difficulty level for your recipe.",
|
161 |
[
|
162 |
-
list(difficulty_dictionary.keys())[0],
|
163 |
-
list(difficulty_dictionary.keys())[1],
|
164 |
list(difficulty_dictionary.keys())[2]
|
165 |
],
|
166 |
captions = [
|
167 |
-
difficulty_dictionary["Quick & Easy"]["description"],
|
168 |
difficulty_dictionary["Intermediate"]["description"],
|
169 |
difficulty_dictionary["Professional"]["description"]
|
170 |
],
|
@@ -181,10 +181,10 @@ fancy_exclusions = ""
|
|
181 |
|
182 |
if st.session_state.selected_difficulty == "Professional":
|
183 |
exclude_fancy = st.checkbox(
|
184 |
-
"Exclude cliche professional ingredients? (gold leaf, truffle, edible flowers, microgreens)",
|
185 |
value=True)
|
186 |
fancy_exclusions = "gold leaf, truffle, edible flowers, microgreens, gold dust"
|
187 |
-
|
188 |
|
189 |
user_inputs = {
|
190 |
"user_direction" : st.session_state.user_direction,
|
@@ -199,21 +199,23 @@ with button_cols_submit[1]:
|
|
199 |
st.button(label='Reset', on_click=clear_inputs, type="secondary", use_container_width=True)
|
200 |
with button_cols_submit[2]:
|
201 |
st.empty()
|
202 |
-
|
203 |
if st.session_state.recipe is not None:
|
204 |
st.divider()
|
205 |
-
print(st.session_state.recipe)
|
206 |
-
recipe =
|
207 |
-
recipe_md = ''
|
208 |
-
recipe_md += f'
|
209 |
-
recipe_md +=
|
210 |
-
|
211 |
-
for ingredient in recipe[
|
212 |
-
recipe_md += f"- {ingredient['name']}
|
213 |
recipe_md += '\n## Instructions:\n'
|
214 |
-
for instruction in recipe[
|
215 |
-
recipe_md += f"{instruction['step_number']}. {instruction['instruction']}
|
|
|
216 |
# recipe['md'] = recipe_md
|
217 |
# recipe['timestamp'] = str(datetime.now())
|
218 |
-
|
219 |
-
st.
|
|
|
|
54 |
def generate_recipe(user_inputs):
|
55 |
with st.spinner('Building the perfect recipe...'):
|
56 |
prompt = create_detailed_prompt(user_inputs['user_direction'], user_inputs['exclusions'], user_inputs['serving_size'], user_inputs['difficulty'])
|
57 |
+
|
58 |
functions = [
|
59 |
{
|
60 |
"name": "provide_recipe",
|
|
|
109 |
}
|
110 |
]
|
111 |
|
|
|
|
|
|
|
112 |
generate_kwargs = dict(
|
113 |
temperature=0.9,
|
114 |
+
max_new_tokens=10000,
|
115 |
top_p=0.9,
|
116 |
+
repetition_penalty=1.0,
|
117 |
+
do_sample=True,
|
118 |
)
|
119 |
|
120 |
+
prompt += f"\nPlease format the output in JSON. The JSON should include fields for 'name', 'description', 'ingredients', and 'instructions', with each field structured as described below.\n\n{functions}"
|
121 |
+
|
122 |
+
response = client.text_generation(prompt, **generate_kwargs)
|
123 |
st.session_state.recipe = response
|
124 |
st.session_state.recipe_saved = False
|
125 |
+
|
126 |
def clear_inputs():
|
127 |
st.session_state.user_direction = None
|
128 |
st.session_state.exclusions = None
|
129 |
st.session_state.serving_size = 2
|
130 |
st.session_state.selected_difficulty = "Quick & Easy"
|
131 |
+
|
132 |
st.title("Let's get cooking")
|
133 |
st.session_state.user_direction = st.text_area(
|
134 |
"What do you want to cook? Describe anything - a dish, cuisine, event, or vibe.",
|
|
|
159 |
st.session_state.selected_difficulty = st.radio(
|
160 |
"Choose a difficulty level for your recipe.",
|
161 |
[
|
162 |
+
list(difficulty_dictionary.keys())[0],
|
163 |
+
list(difficulty_dictionary.keys())[1],
|
164 |
list(difficulty_dictionary.keys())[2]
|
165 |
],
|
166 |
captions = [
|
167 |
+
difficulty_dictionary["Quick & Easy"]["description"],
|
168 |
difficulty_dictionary["Intermediate"]["description"],
|
169 |
difficulty_dictionary["Professional"]["description"]
|
170 |
],
|
|
|
181 |
|
182 |
if st.session_state.selected_difficulty == "Professional":
|
183 |
exclude_fancy = st.checkbox(
|
184 |
+
"Exclude cliche professional ingredients? (gold leaf, truffle, edible flowers, microgreens)",
|
185 |
value=True)
|
186 |
fancy_exclusions = "gold leaf, truffle, edible flowers, microgreens, gold dust"
|
187 |
+
|
188 |
|
189 |
user_inputs = {
|
190 |
"user_direction" : st.session_state.user_direction,
|
|
|
199 |
st.button(label='Reset', on_click=clear_inputs, type="secondary", use_container_width=True)
|
200 |
with button_cols_submit[2]:
|
201 |
st.empty()
|
202 |
+
|
203 |
if st.session_state.recipe is not None:
|
204 |
st.divider()
|
205 |
+
print(st.session_state.recipe,"\n\n\n\n")
|
206 |
+
recipe = ast.literal_eval(st.session_state.recipe)
|
207 |
+
recipe_md = f'# {recipe["name"]}\n\n'
|
208 |
+
recipe_md += f'{recipe["description"]}\n\n'
|
209 |
+
recipe_md += '## Ingredients:\n'
|
210 |
+
# print("ingredients : ",recipe[recipe.index("ingredients"):recipe.index('instructions')][len("ingredients")-1:])
|
211 |
+
for ingredient in recipe["ingredients"]:
|
212 |
+
recipe_md += f"- {ingredient['name']}\n"
|
213 |
recipe_md += '\n## Instructions:\n'
|
214 |
+
for instruction in recipe["instructions"]:
|
215 |
+
recipe_md += f"{instruction['step_number']}. {instruction['instruction']}\n"
|
216 |
+
|
217 |
# recipe['md'] = recipe_md
|
218 |
# recipe['timestamp'] = str(datetime.now())
|
219 |
+
|
220 |
+
st.markdown((recipe_md))
|
221 |
+
st.write("")
|