OmPrakashSingh1704 commited on
Commit
e61e024
·
verified ·
1 Parent(s): 85d63d0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -57
app.py CHANGED
@@ -37,7 +37,8 @@ if 'selected_difficulty' not in st.session_state:
37
 
38
  if 'exclusions' not in st.session_state:
39
  st.session_state.exclusions = None
40
-
 
41
  def create_detailed_prompt(user_direction, exclusions, serving_size, difficulty):
42
  if difficulty == "Quick & Easy":
43
  prompt = (
@@ -55,69 +56,71 @@ def create_detailed_prompt(user_direction, exclusions, serving_size, difficulty)
55
  )
56
  elif difficulty == "Professional":
57
  prompt = (
58
- f"Provide a advanced recipe for {user_direction} that excludes {exclusions} and has a serving size of {serving_size}. "
59
  f"The recipe should push the boundaries of culinary arts, integrating unique ingredients, advanced cooking techniques, and innovative presentations. "
60
  f"The recipe should be able to be served at a high-end restaurant or would impress at a gourmet food competition. "
61
  f"Provide a detailed ingredient list and step-by-step guide that explains the instructions to prepare in detail."
62
  )
63
  return prompt
64
 
 
65
  def generate_recipe(user_inputs):
66
  with st.spinner('Building the perfect recipe...'):
67
- prompt = create_detailed_prompt(user_inputs['user_direction'], user_inputs['exclusions'], user_inputs['serving_size'], user_inputs['difficulty'])
 
68
 
69
  functions = [
70
- {
71
- "name": "provide_recipe",
72
- "description": "Provides a detailed recipe strictly adhering to the user input/specifications, especially ingredient exclusions and the recipe difficulty",
73
- "parameters": {
74
- "type": "object",
75
- "properties": {
76
- "name": {
77
- "type": "string",
78
- "description": "A creative name for the recipe"
79
- },
80
- "description": {
81
- "type": "string",
82
- "description": "a brief one-sentence description of the provided recipe"
83
- },
84
- "ingredients": {
85
- "type": "array",
86
- "items": {
87
- "type": "object",
88
- "properties": {
89
- "name": {
90
- "type": "string",
91
- "description": "Quantity and name of the ingredient"
 
92
  }
93
  }
94
- }
95
- },
96
- "instructions": {
97
- "type": "array",
98
- "items": {
99
- "type": "object",
100
- "properties": {
101
- "step_number": {
102
- "type": "number",
103
- "description": "The sequence number of this step"
104
- },
105
- "instruction": {
106
- "type": "string",
107
- "description": "Detailed description of what to do in this step"
108
  }
109
  }
110
  }
111
- }
112
- },
113
- "required": [
114
- "name",
115
- "description",
116
- "ingredients",
117
- "instructions"
118
  ],
119
- },
120
- }
121
  ]
122
 
123
  generate_kwargs = dict(
@@ -134,19 +137,20 @@ def generate_recipe(user_inputs):
134
  st.session_state.recipe = response
135
  st.session_state.recipe_saved = False
136
 
 
137
  def clear_inputs():
138
  st.session_state.user_direction = None
139
  st.session_state.exclusions = None
140
  st.session_state.serving_size = 2
141
  st.session_state.selected_difficulty = "Quick & Easy"
142
- st.session_state.recipe=None
143
 
144
  st.title("Let's get cooking")
145
  st.session_state.user_direction = st.text_area(
146
  "What do you want to cook? Describe anything - a dish, cuisine, event, or vibe.",
147
- value = st.session_state.user_direction,
148
  placeholder="quick snack, asian style bowl with either noodles or rice, something italian",
149
- )
150
 
151
  st.session_state.serving_size = st.number_input(
152
  "How many servings would you like to cook?",
@@ -175,7 +179,7 @@ st.session_state.selected_difficulty = st.radio(
175
  list(difficulty_dictionary.keys())[1],
176
  list(difficulty_dictionary.keys())[2]
177
  ],
178
- captions = [
179
  difficulty_dictionary["Quick & Easy"]["description"],
180
  difficulty_dictionary["Intermediate"]["description"],
181
  difficulty_dictionary["Professional"]["description"]
@@ -185,9 +189,9 @@ st.session_state.selected_difficulty = st.radio(
185
 
186
  st.session_state.exclusions = st.text_area(
187
  "Any ingredients you want to exclude?",
188
- value = st.session_state.exclusions,
189
  placeholder="gluten, dairy, nuts, cilantro",
190
- )
191
 
192
  fancy_exclusions = ""
193
 
@@ -197,16 +201,16 @@ if st.session_state.selected_difficulty == "Professional":
197
  value=True)
198
  fancy_exclusions = "gold leaf, truffle, edible flowers, microgreens, gold dust"
199
 
200
-
201
  user_inputs = {
202
- "user_direction" : st.session_state.user_direction,
203
  "exclusions": f"{st.session_state.exclusions}, {fancy_exclusions}",
204
  "serving_size": st.session_state.serving_size,
205
  "difficulty": st.session_state.selected_difficulty
206
  }
207
  button_cols_submit = st.columns([1, 1, 4])
208
  with button_cols_submit[0]:
209
- st.button(label='Submit', on_click=generate_recipe, kwargs=dict(user_inputs=user_inputs), type="primary", use_container_width=True)
 
210
  with button_cols_submit[1]:
211
  st.button(label='Reset', on_click=clear_inputs, type="secondary", use_container_width=True)
212
  with button_cols_submit[2]:
 
37
 
38
  if 'exclusions' not in st.session_state:
39
  st.session_state.exclusions = None
40
+
41
+
42
  def create_detailed_prompt(user_direction, exclusions, serving_size, difficulty):
43
  if difficulty == "Quick & Easy":
44
  prompt = (
 
56
  )
57
  elif difficulty == "Professional":
58
  prompt = (
59
+ f"Provide an advanced recipe for {user_direction} that excludes {exclusions} and has a serving size of {serving_size}. "
60
  f"The recipe should push the boundaries of culinary arts, integrating unique ingredients, advanced cooking techniques, and innovative presentations. "
61
  f"The recipe should be able to be served at a high-end restaurant or would impress at a gourmet food competition. "
62
  f"Provide a detailed ingredient list and step-by-step guide that explains the instructions to prepare in detail."
63
  )
64
  return prompt
65
 
66
+
67
  def generate_recipe(user_inputs):
68
  with st.spinner('Building the perfect recipe...'):
69
+ prompt = create_detailed_prompt(user_inputs['user_direction'], user_inputs['exclusions'],
70
+ user_inputs['serving_size'], user_inputs['difficulty'])
71
 
72
  functions = [
73
+ {
74
+ "name": "provide_recipe",
75
+ "description": "Provides a detailed recipe strictly adhering to the user input/specifications, especially ingredient exclusions and the recipe difficulty",
76
+ "parameters": {
77
+ "type": "object",
78
+ "properties": {
79
+ "name": {
80
+ "type": "string",
81
+ "description": "A creative name for the recipe"
82
+ },
83
+ "description": {
84
+ "type": "string",
85
+ "description": "a brief one-sentence description of the provided recipe"
86
+ },
87
+ "ingredients": {
88
+ "type": "array",
89
+ "items": {
90
+ "type": "object",
91
+ "properties": {
92
+ "name": {
93
+ "type": "string",
94
+ "description": "Quantity and name of the ingredient"
95
+ }
96
  }
97
  }
98
+ },
99
+ "instructions": {
100
+ "type": "array",
101
+ "items": {
102
+ "type": "object",
103
+ "properties": {
104
+ "step_number": {
105
+ "type": "number",
106
+ "description": "The sequence number of this step"
107
+ },
108
+ "instruction": {
109
+ "type": "string",
110
+ "description": "Detailed description of what to do in this step"
111
+ }
112
  }
113
  }
114
  }
115
+ },
116
+ "required": [
117
+ "name",
118
+ "description",
119
+ "ingredients",
120
+ "instructions"
 
121
  ],
122
+ },
123
+ }
124
  ]
125
 
126
  generate_kwargs = dict(
 
137
  st.session_state.recipe = response
138
  st.session_state.recipe_saved = False
139
 
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
 
148
  st.title("Let's get cooking")
149
  st.session_state.user_direction = st.text_area(
150
  "What do you want to cook? Describe anything - a dish, cuisine, event, or vibe.",
151
+ value=st.session_state.user_direction,
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?",
 
179
  list(difficulty_dictionary.keys())[1],
180
  list(difficulty_dictionary.keys())[2]
181
  ],
182
+ captions=[
183
  difficulty_dictionary["Quick & Easy"]["description"],
184
  difficulty_dictionary["Intermediate"]["description"],
185
  difficulty_dictionary["Professional"]["description"]
 
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
 
196
  fancy_exclusions = ""
197
 
 
201
  value=True)
202
  fancy_exclusions = "gold leaf, truffle, edible flowers, microgreens, gold dust"
203
 
 
204
  user_inputs = {
205
+ "user_direction": st.session_state.user_direction,
206
  "exclusions": f"{st.session_state.exclusions}, {fancy_exclusions}",
207
  "serving_size": st.session_state.serving_size,
208
  "difficulty": st.session_state.selected_difficulty
209
  }
210
  button_cols_submit = st.columns([1, 1, 4])
211
  with button_cols_submit[0]:
212
+ st.button(label='Submit', on_click=generate_recipe, kwargs=dict(user_inputs=user_inputs), type="primary",
213
+ use_container_width=True)
214
  with button_cols_submit[1]:
215
  st.button(label='Reset', on_click=clear_inputs, type="secondary", use_container_width=True)
216
  with button_cols_submit[2]: